码迷,mamicode.com
首页 > 移动开发 > 详细

【记录】iOS10 点击推送栏的问题

时间:2017-03-21 18:28:50      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:trigger   框架   systemv   blog   style   获取   ini   request   逻辑   

之前做的一个用户点击 推送栏然后处理相应事件是在这里面处理的

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

 

在里面判断是否是后台然后做相应处理,在ios10以下都没什么问题
到10的时候出问题了,点击通知栏的时候不再走这个代理函数了,
反而走了iOS6以下会走的一个代理方法

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo        //iOS10已经废弃

 

这是返璞归真了?


 

原因是iOS10 的新特性

在iOS10下这么处理

#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#import <UserNotifications/UserNotifications.h>
#endif

 

需要添加新的UserNotifications框架
初始化

 if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) // iOS10
    {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
        JPUSHRegisterEntity *entity = [[JPUSHRegisterEntity alloc] init];
        entity.types = (UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound);
        [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
#endif
    }

    //获取registration id
    [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
        if(resCode == 0) {
            NSLog(@"registrationID:%@",registrationID);
        } else {
            NSLog(@"registrationID获取失败,code:%d",resCode);
        }
    }];

 

iOS 10的处理回调结果

#pragma mark - 处理推送消息  iOS 10
// iOS 10 Support 前台处理逻辑
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    NSDictionary *userInfo = notification.request.content.userInfo;
    if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
//    completionHandler(UNNotificationPresentationOptionAlert); // 这个选择是否在前台进行提醒,声音,alert.还有角标.

    NSDictionary *aps = userInfo[@"aps"];
    NSString *message = aps[@"alert"];
    NSLog(@"message = %@", message);
}
// iOS 10 Support 后台处理逻辑
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
        [JPUSHService handleRemoteNotification:userInfo];
    }
    completionHandler();  // 系统要求执行这个方法

    NSDictionary *aps = userInfo[@"aps"];
    NSString *message = aps[@"alert"];
    NSLog(@"message = %@", message);
    }
}

 

【记录】iOS10 点击推送栏的问题

标签:trigger   框架   systemv   blog   style   获取   ini   request   逻辑   

原文地址:http://www.cnblogs.com/L-vincen/p/6595963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!