How to register remote notifications in iOS9
In previous versions, we can use:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:some types]
To register remote notifications, but soon this method is marked as obsolete and prompts us to use another similar method:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
Don't be too happy. Although the registerUserNotificationSettings method still works, the types such as UIRemoteNotificationTypeXXX are quickly marked as obsolete...
Well, in iOS9, registering a remote notification turns into the following code:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound|UIUserNotificationTypeBadge|UIUserNotificationTypeAlert categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications];
Yes, you are not mistaken. The above Code also registers local notifications while registering remote notifications, so we can understand that remote notifications only enable the remote function based on the original local notifications. however, this is just my personal understanding. You are welcome to correct it .;)