Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple Push Notification registration callback for when user refuses initial prompt? [duplicate]

When I call registerForRemoteNotificationTypes on my UIApplication the first time, the user gets the system prompt about allowing this application to send them push notifications. If they say yes, then didRegisterForRemoteNotificationsWithDeviceToken gets called on my app delegate. If they say no, didFailToRegisterForRemoteNotificationsWithError does not get called. Once they say no to that initial prompt, I never get any callback when I try to re-register in the future.

Is this standard behavior? What's the best way to know when they refuse that prompt? Apple's docs on this doesn't say anything useful about this scenario.

like image 606
Tom Hamming Avatar asked Dec 09 '22 17:12

Tom Hamming


1 Answers

The user's decision of which option to select does not affect which callback is used. If the user says "No" you will still successfully get the device token for the user. You can still send push notifications to this device and Apple's feedback service will report them delivered (meaning the feedback service will not tell you they have unsubscribed). The only effect pushing "No" has is to 'hide' push notifications sent to the device for your particular app.

Because of this design decision, the user can reverse this decision by going to settings -> notifications, and re-enable push notifications for your app and receive push notifications without requiring any special re-registration logic from your app or the OS.

EDIT (iOS7): This behavior was noted on iOS 5. When I tested again on iOS 7 I did not receive a device token after pushing "Don't allow". Only once I visited Settings > Notifications > MyApp and enabled notifications did I get a device token.

EDIT (iOS8): In iOS 8 Notification settings are separated from remote notifications, but the behavior is similar to iOS 7. It seems you won't get a device token until notifications are authorized for your app. My app I'm testing with doesn't have the remote notification background mode capability enabled, but presumably if your app did have that you could get a device token even if notifications were not enabled. (I'm having a hard time testing this because it's a huge pain to try to get that notification prompt to appear again.)

like image 51
Asa Avatar answered Dec 11 '22 05:12

Asa