ios 开发iOS消息推送

iOS远程推送之(三):点击通知横幅启动应用

2017-07-04  本文已影响306人  KODIE

导读

iOS远程推送之(一):APNs原理和基本配置
iOS远程推送之(二):角标applicationIconNumber设置

点击横幅启动应用

我们应用的启动方式有很多种,主要的方式如下:

简说:

PS: UIApplicationLaunchOptionsRemoteNotificationKey的说明如下:

The presence of this key indicates that a remote notification is available for the app to process. 
释义:这个键的存在表明,远程通知是可供应用的过程。
The value of this key is an NSDictionary containing the payload of the remote notification. 
释义:这个字典当中的这个键对应的值包含了推送消息负载(payload)
See the description of application:didReceiveRemoteNotification: for further information about handling remote notifications.
释义:看这个方法的描述能够进一步的了解处理盐城通知的相关信息

代码说明:

- (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;
}
//这个是最新的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;
}
- (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) {
        //如果有值,说明是通过远程推送来启动的
        //[UIApplication sharedApplication].keyWindow是拿不到值的
    }
    return YES;
}

PS:以上中keyWindow是拿不到值的,所以这里的话我一般的做法是在根控制器创建完成之后发送一个通知出来,然后Appdelegate中接收通知,然后实现跳转对应的控制器或者界面

扩展:launch_options_keys

UIApplicationLaunchOptionsURLKey

UIApplicationLaunchOptionsSourceApplicationKey

UIApplicationLaunchOptionsRemoteNotificationKey

UIApplicationLaunchOptionsLocalNotificationKey

UIApplicationLaunchOptionsAnnotationKey

UIApplicationLaunchOptionsLocationKey

UIApplicationLaunchOptionsNewsstandDownloadsKey

UIApplicationLaunchOptionsBluetoothCentralsKey

UIApplicationLaunchOptionsBluetoothPeripheralsKey

UIApplicationLaunchOptionsShortcutItemKey

UIApplicationLaunchOptionsUserActivityDictionaryKey

UIApplicationLaunchOptionsUserActivityTypeKey

上一篇下一篇

猜你喜欢

热点阅读