大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处.
假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;)
在以往的版本号中,我们能够通过:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:some types]
来注冊远程通知,只是非常快该方法就被标记为废弃,而且提示我们要用还有一个相似的方法:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
别高兴的太早,尽管registerUserNotificationSettings方法如今照样工作,只是当中的诸如UIRemoteNotificationTypeXXX之类的类型非常快又被标记为废弃…
好吧,在iOS9中,注冊远程通知变成了例如以下相似的代码:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound|UIUserNotificationTypeBadge|UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
额,你没看错,以上代码在注冊远程通知的同一时候还注冊了本地通知,所以我们能够理解为远程通知仅仅是在原有本地通知基础上开启了远程功能.只是这仅仅是我个人的理解,欢迎纠错. ;)