導(dǎo)讀
iOS遠(yuǎn)程推送之(一):APNs原理和基本配置
iOS遠(yuǎn)程推送之(二):角標(biāo)applicationIconNumber設(shè)置
點擊橫幅啟動應(yīng)用
我們應(yīng)用的啟動方式有很多種,主要的方式如下:
- 一種是在HomeScreen上正常手動點擊圖標(biāo)打開進(jìn)入到應(yīng)用中
- 一種是通過其他應(yīng)用調(diào)起該應(yīng)用
- 一種是通過點擊通知橫幅來啟動應(yīng)用
簡說:
- 第一種很正常的在didFinishLaunchingWithOptions里面處理就OKay的
- 第二種是通過openURL的方式打開的,那么在對應(yīng)的openURL方法來處理相關(guān)內(nèi)容的
- 第三種是通過判斷didFinishLaunchingWithOptions中的參數(shù)launchOptions中的UIApplicationLaunchOptionsRemoteNotificationKey來處理相關(guān)的消息內(nèi)容
PS: UIApplicationLaunchOptionsRemoteNotificationKey的說明如下:
The presence of this key indicates that a remote notification is available for the app to process.
釋義:這個鍵的存在表明,遠(yuǎn)程通知是可供應(yīng)用的過程。
The value of this key is an NSDictionary containing the payload of the remote notification.
釋義:這個字典當(dāng)中的這個鍵對應(yīng)的值包含了推送消息負(fù)載(payload)
See the description of application:didReceiveRemoteNotification: for further information about handling remote notifications.
釋義:看這個方法的描述能夠進(jìn)一步的了解處理鹽城通知的相關(guān)信息
代碼說明:
- 第一種:didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[ViewController alloc] init];
[self.window makeKeyAndVisible];
//code here...
return YES;
}
- 第二種openURL:
//這個是最新的iOS9之后的
-(BOOL) application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
{
[[KODSDK defaultSDK] kodDealWithApplication:app openURL:url sourceApplication:options[@"UIApplicationOpenURLOptionsSourceApplicationKey"] annotation:options[@"UIApplicationOpenURLOptionsOpenInPlaceKey"]];
return YES;
}
//這個是iOS9之前的,9之后廢棄
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
[[KODSDK defaultSDK] kodDealWithApplication:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
return YES;
}
- 第三種:UIApplicationLaunchOptionsRemoteNotificationKey
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[ViewController alloc] init];
[self.window makeKeyAndVisible];
NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil) {
//如果有值,說明是通過遠(yuǎn)程推送來啟動的
//[UIApplication sharedApplication].keyWindow是拿不到值的
}
return YES;
}
PS:以上中keyWindow是拿不到值的,所以這里的話我一般的做法是在根控制器創(chuàng)建完成之后發(fā)送一個通知出來,然后Appdelegate中接收通知,然后實現(xiàn)跳轉(zhuǎn)對應(yīng)的控制器或者界面
UIApplicationLaunchOptionsURLKey
UIApplicationLaunchOptionsSourceApplicationKey
UIApplicationLaunchOptionsRemoteNotificationKey
UIApplicationLaunchOptionsLocalNotificationKey
UIApplicationLaunchOptionsAnnotationKey
UIApplicationLaunchOptionsLocationKey
UIApplicationLaunchOptionsNewsstandDownloadsKey
UIApplicationLaunchOptionsBluetoothCentralsKey
UIApplicationLaunchOptionsBluetoothPeripheralsKey
UIApplicationLaunchOptionsShortcutItemKey
UIApplicationLaunchOptionsUserActivityDictionaryKey
UIApplicationLaunchOptionsUserActivityTypeKey