iOS 10 推送Tips

1.注册方式:
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
 [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
   if (!error) {
     NSLog(@"succeeded!");
   }
 }];
 center.delegate = self;
 [[UIApplication sharedApplication] registerForRemoteNotifications];```
#####2.获取用户设置状态
```objectivec
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { NSLog(@"%@",settings);}];
3.新增方法
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
 completionHandler(UNNotificationPresentationOptionBadge);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
 NSDictionary *userinfo = response.notification.request.content.userInfo;
   if (userinfo && [userinfo isKindOfClass:[NSDictionary class]]) {
   }
}
4.配置问题
  • iOS的推送注册方式与之前有所不同,UNUserNotificationCenter 一定更要设置一下delegate,否则不会调用新增的两个delegate方法。

你可能感兴趣的:(iOS 10 推送Tips)