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.
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.
It's an old question, but I've just encountered this issue and it seems to be related to remote-notification background mode. application:didRegisterForRemoteNotificationsWithDeviceToken
is called on my iPhone before accepting push notification permission only when this background mode is turned on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With