APNS didRegisterForRemoteNotifications called before user allows notifications on iOS
apple-push-notifications, ios
Solution
This is from Apple docs.
When you send this message, the device initiates the registration process with Apple Push Service. If it succeeds, the application delegate receives a device token in the application:didRegisterForRemoteNotificationsWithDeviceToken: method; if registration doesn’t succeed, the delegate is informed via the application:didFailToRegisterForRemoteNotificationsWithError: method. If the application delegate receives a device token, it should connect with its provider and pass it the token.
AND
The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.
I think what you are observing is normal. There is no mention that `application:didRegisterForRemoteNotificationsWithDeviceToken` will only be called if user grants permission. I think you can optimize it by caching device token in NSUserDefaults and in this method check if the new token not equal to cached token.
Problem
I'm working on some iOS apps, all under the same publisher, that all have push notifications enabled. When I call `registerForRemoteNotificationTypes`, I get the user prompt to allow or disallow push notifications, but I `application:didRegisterForRemoteNotificationsWithDeviceToken:` gets called with token data before the user chooses an option. And it gets called again when they press OK. Is this normal? Also of note: multiple apps appear to get the same token when running on the same device.