Allen Allen - 24 days ago 5x
iOS Question

Remote Notifications in iOS 10

So we all know that Apple has introduced the UserNotifications Framework this summer and it's great.
And according to Apple's API references and a WWDC Session about this framework, we now have a new way to register for push notification as follows:

UNUserNotificationCenter.current().requestAuthorization(options: [options], completionHandler: {})

But clearly this method is not gonna get a deviceToken from the APNs server so Apple has kept some of the API in the UIKit as follows:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){}

That's the two method for registering and getting the deviceToken for Remote Notifications.

So it's getting ambiguous that if I only want to register for Remote Notifications will I still have to do the
thing? Or is the
just for Registering Local Notifications?

Plus if I need to implement both of them even if I only want to register for Remote Notifications, where should I write the
? Should I write it in the
or should I just write it outside as if this two
thing are running in parallel?


If you only want to register for remote notifications, you still need to requestAuthorization, because this is how you ask the user if you may display alerts and sounds, which applies to both local and remote notifications.

You can call registerForRemoteNotifications outside of your requestAuthorization completion handler and allow them to run in parallel.


registerForRemoteNotifications gets you the user's token whether or not they've approved push notifications.

How is this useful if the user declined?

At any time in the future (after your app has called requestAuthorization to indicate that it would like to send notifications), the user can go into the Settings app, tap your app, and turn on the Allow Notifications setting.

If you are already sending notifications using the user's token, those notifications will begin coming through when the user turns on permission, without any action needed from you.