APNS didRegisterForRemoteNotifications is called before the user allows notifications in iOS

I am working on some iOS apps that are under the same publisher, and all have push notifications. When I call registerForRemoteNotificationTypes , I get a user invitation to enable or disable push notifications, but I application:didRegisterForRemoteNotificationsWithDeviceToken: is called with marker data before the user selects an option. And it is called again when they click OK. This is normal?

Also note: multiple applications seem to get the same token when working on the same device.

+7
source share
2 answers

This is from Apple docs.

When you send this message, the device initiates registration with the Apple Push Service. If this succeeds, the delegate application receives the device token in the application: didRegisterForRemoteNotificationsWithDeviceToken: method; if registration fails, the delegate is informed through the application: didFailToRegisterForRemoteNotificationsWithError: method. If the application delegate receives a device token, he must connect with his provider and pass the token to him.

and

The first time a push-enabled app registers for push notifications, iOS asks the user if they want to receive notifications for this app. Once the user has responded to this warning, he will not be presented again if the device is not restored or the application has not been deleted for at least a day.

I think you are observing normally. There is no mention that application:didRegisterForRemoteNotificationsWithDeviceToken will only be called if the user grants permission. I think you can optimize it by caching the device token in NSUserDefaults, and in this method check if the new token matches the cached token.

+6
source

This is an old question, but I just ran into this problem and seems to be related to the background of remote notifications. application:didRegisterForRemoteNotificationsWithDeviceToken is called on my iPhone before accepting push notification permission only when this background is turned on.

+2
source

All Articles