iOS10下app运行中,但是处于后台,点击通知问题

来源:互联网 发布:地图软件电脑版 编辑:程序博客网 时间:2024/06/03 07:42
/** *  当app完全离线状态,点击通知栏的通知,会调用该方法此时launchOptions有值 */- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    //APNS注册通知    if ([UIDevice currentDevice].systemVersion.doubleValue<8.0) {        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];    }    else {        [[UIApplication sharedApplication] registerForRemoteNotifications];        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil]];    }    NSLog(@"%@",launchOptions);    //判断是否由远程消息通知触发应用程序启动    if (launchOptions) {        //获取应用程序消息通知标记数(即小红圈中的数字)        NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;        self.window.rootViewController.view.backgroundColor = [UIColor redColor];        if (badge>0) {            //如果应用程序消息通知标记数(即小红圈中的数字)大于0,清除标记。            badge--;            //清除标记。清除小红圈中数字,小红圈中数字为0,小红圈才会消除。            [UIApplication sharedApplication].applicationIconBadgeNumber = badge;            NSDictionary *pushInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@,您可以在消息设置那里进行查看",[[pushInfo objectForKey:@"aps"] objectForKey:@"alert"]] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];            [alert show];        }    }    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;    return YES;}/** *  当app出于前台的时候,接收到消息,会调用下面这个方法. */- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{    NSLog(@"%s", __func__);    self.window.rootViewController.view.backgroundColor = [UIColor greenColor];}/** *  当app在运行中但是出于后台的时候,点击通知栏的通知,app从后台回到前台会触发下面这个方法而不是上面这个 *  虽说该方法提示已经过期,这是不是iOS10的一个bug呢? */- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{    NSLog(@"%s", __func__);    self.window.rootViewController.view.backgroundColor = [UIColor greenColor];}

这里写图片描述

0 0
原创粉丝点击