【发布时间】:2017-04-19 15:43:30
【问题描述】:
我使用 APNS,它在 iOS 9 上运行良好。 随着 iOS10 上新的推送 API 更改,我无法注册推送通知,因此我插入了下一个更改:
- 在目标功能选项卡中启用推送通知。
-
在 didFinishLaunchingWithOptions 我们检查操作系统版本并注册如下:
if (SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")) { //ios 10 Notifiction UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if( !error ){ [[UIApplication sharedApplication] registerForRemoteNotifications]; NSLog(@"iOS 10 push notification register successfully "); } }]; } else { // iOS 8-9 Notifications [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; NSLog(@"iOS 9 push notification register successfully "); }
通过这些更改,我设法在 iOS 9 和 iOS 10 中执行注册,但我遇到了几个问题:
- 在目标功能选项卡中启用推送通知后,尽管注册已成功完成,但推送通知在 iOS 9 上停止工作。
- 虽然注册成功,但推送在 iOS 10 上根本不起作用。
请记住,如果我在目标功能选项卡中关闭推送通知(使用相同的代码),推送将在 iOS 9 上恢复工作,但我无法在 iOS 10 上注册 APNS。
【问题讨论】:
-
也已经尝试过了。在功能选项卡中启用推送通知,添加 UserNotifications 框架和 UNUserNotificationCenterDelegate,检查操作系统版本并在两个操作系统版本中成功注册。问题是 didReceiveRemoteNotification 没有调用。我不需要知道通知中的用户操作,但我也实现了 didReceiveRemoteNotification:userInfo fetchCompletionHandler
标签: ios objective-c push-notification