178

I am developing an app with push notifications. To check all possible ways of user interaction, I'd like to test my app when a user declines to have push notifications enabled for my app during the first start.

The dialog (initiated by registerForRemoteNotificationTypes), however, appears only once per app. How do I reset the iPhone OS's memory of my app. Deleting the app and reinstalling doesn't help.

hanno
  • 6,401
  • 8
  • 48
  • 80

14 Answers14

306

Technical Note TN2265: Troubleshooting Push Notifications

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 setting the system clock forward a day or more, turning the device off completely, then turning the device back on.

Update: As noted in the comments below, this solution stopped working since iOS 5.1. I would encourage filing a bug with Apple so they can update their documentation. The current solution seems to be resetting the device's content and settings.

Update: The tech note has been updated with new steps that work correctly as of iOS 7.

  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.

UPDATE as of iOS 9

Simply deleting and reinstalling the app will reset the notification status to notDetermined (meaning prompts will appear).

Thanks to the answer by Gomfucius below: https://stackoverflow.com/a/33247900/704803

andrewtweber
  • 24,520
  • 22
  • 88
  • 110
ianolito
  • 3,651
  • 1
  • 19
  • 18
  • 16
    Has anyone tried this w/ iOS 5.1? I have followed these steps exactly and I still can't get the device to reset it... I have even tried setting the clock on my Mac forward before installing it via Xcode. – nrj Mar 21 '12 at 19:21
  • 1
    Ditto... I didn't get a prompt. – serverpunk Mar 27 '12 at 05:29
  • 2
    Apple added a new requirement to the AppStore submissions guidelines, which relies on the application to show the prompt. This may suggest that the automatic prompt has been removed in iOS 5.1. However there is no API to query the notification center settings, so not sure what would be the purpose of the prompt anyway. See my response to a similar issue: http://stackoverflow.com/questions/10191006/objective-c-detect-when-user-change-the-apps-notifications-settings/10191220#10191220 – Greg Apr 18 '12 at 12:10
  • 1
    After playing arround with the date settings I noticed this only worked for me when I changed the date with at least *one month* further as setting *one day* did not work for me. Hope this helps! – Vincent Cohen Feb 02 '13 at 11:16
  • Maybe I'm not doing it right, but I can't get this work at all, no matter how far forward I set the clock. I've filed a bug with Apple, but I'd encourage others to do the same. – patr1ck Feb 20 '13 at 08:48
  • Awesome... The feeling you get when something starts working after scratching head for a long time is awesome and I feel achieved world.. +1 for the solution – Dinakar Feb 26 '14 at 10:46
  • 11
    This is ridiculous. Doesn't Apple realize that developers or even users might want to be able to reset these things without using a really bad workaround? – sudo May 15 '14 at 01:32
  • Works on iOS8 with only one change – joel1di1 Jan 06 '15 at 01:12
  • 1
    This applies also for local notifications. – Jonny Mar 17 '15 at 06:02
  • What about the simulator? – oky_sabeni Apr 03 '15 at 05:24
  • I recommend doing this in the simulator because you can "restart" it a lot faster than an actual device. – Andrew Apr 06 '15 at 23:25
  • How do you do it in the simulator? I don't see anywhere in the settings to move the clock forward one day. – Rafi Jun 19 '15 at 03:43
  • To perform this in the simulator, bring up the simulator in question. Click on "iOS Simulator" from the menu and then click on "Reset Content and Settings". This clears everything which includes permissions. – C6Silver Jul 11 '15 at 21:54
  • 2
    When I try this in the simulator, I'm getting the error Code=3010 "remote notifications are not supported in the simulator" – tzer Aug 11 '15 at 13:42
  • So when do I turn the clock back to the correct day? Or do I just keep changing it forward? But then my data will be all wrong coz of wrong date. – Van Du Tran Aug 17 '15 at 16:51
  • 1
    Actually, on iOS 7+, you don't need to restart twice. Just uninstall your app, set your device's date 24hrs ahead and then restart your device. There you go. – Caio Dec 23 '15 at 11:56
  • For anyone who can't immediately figure out how to set the Date Forward, turn off the switch "Set Automatically" when on the Date & Time page. – trixmasta Dec 28 '15 at 16:17
  • after I run my app with UIApplication.shared.unregisterForRemoteNotifications() the variable of UIApplication.shared.isRegisteredForRemoteNotifications looks false but then after I try to register, it remember the old settings, interesting – eemrah Nov 02 '22 at 14:11
49

Another just for testing solution to this is by simply changing your bundle id. Just don't forget to change it back once you're done!

capikaw
  • 12,232
  • 2
  • 43
  • 46
  • 13
    Don't you also need to create a certificate for the new app id in order to test it? – Tony Jan 12 '15 at 21:40
  • 1
    This would only work if your'e using wildcard based provisioning profiles - otherwise, you would need to create a profile for the new bundle. – Zorayr May 18 '15 at 02:03
  • Even if you need to create a new profile, that's merely clicking the "Fix it" button and waiting a few seconds -- much faster than going through all those reboot cycles. – Ilya Oct 06 '15 at 08:51
  • this is the fastest solution ! It works pretty well for me ! When changing your bundle_id you won't be able to sign the app with the same "provisioning profiles". But don't worry, in xCode (my version 7.1.1), you can click on "fix it" and it do the job. As well, don't forget the "Capabilities" onglet, where you can have several items to "fix" (by clicking on the "fix it" button) and then, it will works very well ! – Dam Fa Nov 23 '15 at 22:06
  • This answer is a legit option but still a hack-fix for a foolish situation from Apple. I'm not modifying the bundleID, nor switching the device clock. Just as appropriate, any developer could write some short code showing a UIAlertView that asks "Allow push notifications?" .. Yes = call the register method; No = call didFailToRegisterForRemoteNotificationsWithError (etc).. that's my own solution, my take-away after reading this Q&A. Technically, it's the best way, to give users awareness of privacy info... WHY push must be enabled or optional. – Tom Pace Dec 20 '16 at 17:00
39

On iOS 9.0.2, I'm getting the "register push notification alert" every time I delete the app and reinstall it. This is true for both AppStore production downloads and adhoc mode.

UPDATE: It is confirmed this is working for iOS 9.x

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

As already noted the approach for resetting the notification state for an app on a device is changed for iOS5 an newer.

This works for me on iOS6:

  • Remove the app from the device
  • Set the device datetime two days or more ahead
  • Restart the device
  • Set the device datetime two days or more ahead
  • Restart the device
  • Install and run the app again

However this will only make the initial prompt appear again - it will not remove any other push state related stuff.

micmdk
  • 951
  • 1
  • 8
  • 12
  • Worked for me too on ios7, you have to change the date twice once doesn't work – Nath Nov 14 '13 at 14:01
  • 1
    Thank you! This even works on iOS 8 (I had to reset the push permissions for Twitter.app, because it did not have the "App icon badges" setting in it's preference pane in the Settings). – gklka Oct 13 '14 at 07:09
9

The plist: /private/var/mobile/Library/RemoteNotification/Clients.plist

... contains the registered clients for push notifications. Removing your app's entry will cause the prompt to re-appear

Erik Johnson
  • 155
  • 1
  • 11
    useless answer if you develop for the App Store – samvermette Jul 20 '10 at 20:42
  • 21
    If this is possible for jailbreakers, it should be possible for developers to do on a non-jailbroken phone, right? And it's NOT a useless answer, because this isn't something you'd put in an app for submission to the store. It's for developers to do WHILE TESTING. – Oscar Oct 30 '12 at 08:00
  • 1
    This file is not part of iOS 5.x. – gmogames Nov 26 '12 at 01:41
  • See an updated answer as part of this question: http://stackoverflow.com/questions/13021066/reset-push-notification-permission-setting-in-ios5 – AriX Mar 08 '13 at 07:51
8

Doing it programmatically seems to work for me everytime. I have a build with the following line uncommented:

 [[UIApplication sharedApplication] unregisterForRemoteNotifications];

I run it every time I want to unregister from PN. You might have to end the app explicitly from the recents list and play around with the Notification Center in Settings app to get it right.

Also, the UI prompt asking the user to register for PN may not show up. Not sure if has been disabled in any of the recent iOS versions.

dagnytaggart
  • 511
  • 7
  • 17
6

I agree with micmdk.. I had a development environment setup with Push Notifications and needed a way to reset my phone to look like an initial install… and only these precise steps worked for me… requires TWO reboots of Device:

From APPLE TECH DOC:

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.

lepert
  • 515
  • 6
  • 8
  • This has been mentioned as no longer working in another answer. – Beau Nouvelle Jan 28 '15 at 02:19
  • It works just fine. What stopped working in iOS 5.1 was the *old* version of that other answer, which left out the reboot between deleting the app and setting the clock ahead. – dgatwood May 13 '15 at 00:17
5

As ianolito said, setting the date should work:

You can achieve the latter without actually waiting a day by setting the system clock forward a day or more, turning the device off completely, then turning the device back on.

I noticed on my device (iPhone 4, iOS 6.1.2) setting the system clock a day forward or even a few days did not work for me. So I set the date forward a month and then it did work and my application showed the notifications prompt again.

Hope this helps for anyone, it can be kind of head aching!

Vincent Cohen
  • 878
  • 7
  • 28
  • 1
    Please don't answer with "Latest OS" – it changes all the time. This behaviour appears still broken in 6.1.2, but perhaps it worked in 6.0.1? – patr1ck Feb 21 '13 at 06:35
  • Edited the answer, still have this in 6.1.2 yes and before in 6.0.1 too. It only works for me if I at least set the date +1 month. – Vincent Cohen Feb 25 '13 at 17:37
  • 1
    I had also heard the 24 hour thing, so tried it and it didn't work doing 2 days in advanced. Set it to like 3 months from now and the permission popup appeared again! Thanks! – marcshilling Apr 01 '15 at 18:18
  • Old post but glad to see it is still of help! Good luck :) – Vincent Cohen Apr 01 '15 at 20:26
3

The same tech note as refered to in the accepted answer (TN2265 - Troubleshooting Push Notifications) has since been updated with a solution for iOS 5 and above.

In short: create a backup and restore from it every time.

On iOS 5 and later, reset the push notifications permissions alert by restoring the device from a backup (r. 11450187). Here are the steps to do this efficiently:

  1. Use the Xcode Organizer to install your app on the device. The key is to install the app for the first time without running it.
  2. Use iTunes to back up the device.
  3. Run the app. The push notifications permissions alert will be presented.
  4. When you want to reset the push notifications permissions alert, restore the device from the backup you created in the first step.
Community
  • 1
  • 1
David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
  • It might have recommended that at one time, but it no longer does. The current recommendation is to delete the app, reboot, set the clock forward, reboot, optionally set the clock back to the correct date and time, and run the app. – dgatwood May 13 '15 at 00:19
3

I have wondered about this in the past and came to the conclusion that it was not actually a valid test case for my code. I don't think your application code can actually tell the difference between somebody declining notifications the first time or later disabling it from the iPhone notification settings. It is true that the user experience is different but that is hidden inside the call to registerForRemoteNotificationTypes.

Calling unregisterForRemoteNotifications does not completely remove the application from the notifications settings - though it does remove the contents of the settings for that application. So this still will not cause the dialog to be presented a second time to the user the next time the app runs (at least not on v3.1.3 that I am currently testing with). But as I say above you probably should not be worrying about that.

kharrison
  • 3,412
  • 1
  • 24
  • 19
2

The Apple Tech Note also described you can restore the device to reset the Push Notification dialog.

It does not say that you can also use the option "General -> Reset -> Erase All Content And Settings" on the device itself (iOS 5.x).

hotdogsoup.nl
  • 1,078
  • 1
  • 9
  • 22
  • 1
    For what it's worth: I just tried 'erase all settings', and that didn't work. Trying all-content-and-all-settings... – Groxx May 25 '12 at 07:51
  • 8
    And "all content and settings" does indeed work, thanks! But holy nuclear option, Batman! That's absolutely insane. – Groxx May 25 '12 at 08:26
  • 97
    I've heard buying a new device also clears the push notification warning! – samvermette Jun 06 '12 at 20:45
  • I tried buying a new device, but that didn't work either. After taking the new device to the genius bar, they worked some magic and fixed for more money... I'm surprised after so many years Apple still hasn't provided a practical and simple way to reset push permissions. It's ridiculous – Chris Aug 02 '15 at 17:18
2

I recently ran into the similar issue with react-native application. iPhone OS version was 13.1 I uninstalled the application and tried to install the app and noticed both location and notification permissions were not prompted.

On checking the settings, I could see my application was enabled for location(from previous installation) however there was no corresponding entry against the notification Tried uninstalling and rebooting without setting the time, it didn't work. Btw, I also tried to download the Appstore app, still same behavior.

The issue was resolved only after setting the device time.

RUppal
  • 71
  • 4
1

In addition to the answer of ianolito.

Had the same issue with an app I downloaded a year ago and denying push notification initially. Now wanting push notifications back, these steps worked for me on iOS 7 beta. Not sure which point(s) triggered it exactly.

  • Close and delete the app.
  • Go to your iCloud settings and delete the app from the iCloud. Do this on all other devices where you have iCloud backup for apps enabled. After deactivating and deleting make a fresh backup. The app should not be listed any more under the backups. (This is maybe why the Technical Note from Apple described by ianolito stopped working in iOS 5, since iCloud was introduced in iOS 5 and many have iCloud backup for apps enabled.)
  • Go to your time settings and set the time more than 1 month ahead.
  • Switch the iPhone off (no reset).
  • Wait a minute, switch it on again and download the app again.
  • Start the app and I was presented the dialog again.
  • Enable app backup again, since it is still deactivated. Correct the time.

Thank god I did not have to "Erase All Content And Settings". Maybe it will help someone.

Masa
  • 3,241
  • 1
  • 16
  • 12
-1

After hours of searching, and no luck with the suggestions above, this worked like to a charm for 3.x+

override func viewDidLoad() {
        super.viewDidLoad()


            requestAuthorization()

}

func requestAuthorization() {

        if #available(iOS 10.0, *) {

            UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
                print("Access granted: \(granted.description)")
            }

        } else {
            // Fallback on earlier versions
        }

    }
Felecia Genet
  • 367
  • 4
  • 3