52

I am building an app that is heavily relies on APN. Upon the very first start of my app, iOS asks if this app is allowed to use APN (as a result of registerForRemoteNotificationTypes: call). However once dismissed, this dialog is never popping up back. I have to manually go to Settings->Notifications->MyApp to enable/disable things there. So is there a way to avoid this hustle and actually experience what user will experience upon the very first start every time I start my app in debug mode?

Eran
  • 387,369
  • 54
  • 702
  • 768
Schultz9999
  • 8,717
  • 8
  • 48
  • 87
  • check this link http://stackoverflow.com/questions/10191006/objective-c-detect-when-user-change-the-apps-notifications-settings – Pawan Rai Feb 05 '14 at 10:03
  • You should mark this as answered, since the below method does work (for ios 7.0+). – LucasA Jul 01 '14 at 17:42
  • @Schultz9999 Eran's answer covers what you asked. Currently the only way to set up a "first time" start is following the below steps. I reproduced them and it worked. Documentation provided by Apple: https://developer.apple.com/library/ios/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG42 – LucasA Jul 02 '14 at 16:11
  • Why is there a bounty here? Isn't the accepted answer enough? – Gil Sand Apr 16 '15 at 08:26

8 Answers8

93

Here's how Apple say you can do it:

Resetting the Push Notifications Permissions Alert on iOS

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.

If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by following these steps:

  1. Delete your app from the device.

  2. Turn the device off completely and turn it back on.

  3. Go to Settings > General > Date & Time and set the date ahead a day or more.

  4. Turn the device off completely again and turn it back on.

brandonscript
  • 68,675
  • 32
  • 163
  • 220
Eran
  • 387,369
  • 54
  • 702
  • 768
  • 8
    Wow... Good work Apple :) But thank you! Still better than nothing. I'll give it a shot. – Schultz9999 Feb 05 '14 at 18:26
  • 1
    Side effect: If you do this on an iDevice that have iMessages enabled, moving the clock one day into the future will disable iMessage. So after you have completed the above and reset the clock, remember to enable iMessages again or you will not be able to send or receive – Thomas Watson Mar 16 '14 at 18:39
  • 5
    Something I've just found: After you reset the permissions, whenever the prompt shows again, you can turn off/on the phone instead of answering the prompt, and that'll make it prompt again on the next app run. Useful for changing code trying to figure out if/when certain code-paths would cause the prompt. – adam.wulf Jan 17 '15 at 06:50
  • @ThomasWatson: would turning on airplane mode avoid iMessages to be turned off? – Mojo66 Jul 18 '15 at 10:14
  • @Mojo66 I think it would have the same effect, as turning iMessage on/off isn't related to your online status - but give it a try... I haven't tested it – Thomas Watson Jul 18 '15 at 21:42
  • Sorry to bother. Can you please take a look [here](https://stackoverflow.com/questions/44442192/should-i-update-my-app-upon-receiving-payload-or-i-should-always-update-it-by-a) and see if you can answer it? @eran – mfaani Jun 15 '17 at 19:35
27

Since time is money and the other methods take FOREVER—just change your bundle ID over and over while debugging, each time notifications will get queried fresh. Once you are satisfied with code return to original bundle ID.


Key Notes from comments below:

  • Temporarily turn off all other Capabilities (like IAP) to get around needing to change the provisioning profile.
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
  • 1
    I think this is definitely best, fastest and safest way to get app back to it's initial state. – ooxio May 29 '15 at 09:34
  • 1
    But wouldn't you need to change the provisioning profile all the time? – Van Du Tran Aug 17 '15 at 17:18
  • @VanDuTran I don't have to, push still worked for me. But even if you had to, it would be so much faster than the current marked solution. Haha! – Albert Renshaw Aug 17 '15 at 18:25
  • @AlbertRenshaw Oh my, the current solution doesn't even work for me... I set it to two days forward.. – Van Du Tran Aug 17 '15 at 18:40
  • 2
    Temporarily turn off all other Capabilities (like IAP) to get around needing to change the provisioning profile. – rizzes Jan 13 '16 at 19:41
24

On iOS 9.x, you can get the prompt every time you delete the app and reinstall it. This is true for both AppStore production downloads and adhoc mode. The device token will be unique each time.

@chengsam verified this is true in iOS 10 as well. @WongWray verified this is true in iOS 11 as well.

Genki
  • 3,055
  • 2
  • 29
  • 42
9

On IOS10 i can now get the prompt again by just deleting the app.

David Aanis
  • 93
  • 1
  • 3
6

Currently their is no programmatic way to prompt a user to re-accept Push Notificaitons after they have already decided to say no.

You should simply check if you have been granted access, and if not display a view reminding the user to manually give permission in the privacy settings in order to enable push notification features of your application.

Woodstock
  • 22,184
  • 15
  • 80
  • 118
  • I am not even looking for a way to ask the same thing. All I need is basically bring the system to the initial state. But I got your point. That's really what I am doing later by calling `[[UIApplication sharedApplication] enabledRemoteNotificationTypes]`. The problem is that I wanted to act differently upon app startup. I can try to use the same approach I suppose. – Schultz9999 Feb 05 '14 at 08:32
  • I understand what you're trying to do, but unfortunately it's not possible (unless there are some undocumented private APIs to do so). – Woodstock Feb 05 '14 at 08:33
2

If you're just testing that the Push Notifications prompt appears correctly, use the simulator. All you need to do is uninstall the app and reinstall, and the prompt will appear again when you try to register for push notifications.

mofojed
  • 1,342
  • 9
  • 11
  • This is definitely better that doing the whole change-date-reset dance. Although it only works on iOS 12 and not 13 :/ – rgkobashi Sep 10 '20 at 04:59
1

My problem was not registering for UserNotificationSettings. This allowed the APN to work but not the background sound or badge.

      [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
buckleyJohnson
  • 459
  • 4
  • 12
1

From iOS 13 and above you need to do the whole changing-date-reset thing, as pointed out by Eran.

From iOS 12 and below, uninstalling the app is enough. This also works on simulator, you wont get token though since simulator does not support push notifications.

rgkobashi
  • 2,551
  • 19
  • 25