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

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

- (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);
    }
}

 

转载于:https://www.cnblogs.com/L-vincen/p/6595963.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值