4

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.

Tom Hamming
  • 10,577
  • 11
  • 71
  • 145
  • 3
    No, my question is how to know that they've said no, not how to re-ask them later. – Tom Hamming Mar 01 '13 at 22:31
  • In that case, perhaps http://stackoverflow.com/questions/5399137/reading-notification-flag-in-settings-application-inside-my-iphone-application is the answer to your question. – Asa Oct 04 '13 at 21:10

1 Answers1

14

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.)

Asa
  • 1,466
  • 9
  • 27
  • 3
    I don't believe this is completely true. In my experience, your app does *not* get a device token if the user hits "don't allow." – AriX Dec 23 '13 at 01:54
  • 4
    I notice the same thing in iOS 7. It must have been changed at some point. Thanks AriX! – Asa Dec 31 '13 at 19:16