5

I am developing an app that uses push notifications, and testing on a device with iOS 5.1.1. I would like to test the scenario where the user is prompted about push notifications during the app's first run. The dialog appears the first time I call registerForRemoteNotificationTypes, but never appears again, even if the app is re-installed from scratch. How can I clear the setting so that the dialog will appear again?

The same question was posted before, but the answers do not work for iOS 5 or later, as noted in the comments there.

Apple's documentation says to uninstall the app and mess with the clock to make it look like the app was uninstalled for a day, but this does not work on iOS5.

Another answer suggested running General -> Reset -> Erase All Content And Settings - I tried this, but it froze my device and I ended up having to power-cycle it. In any case, this is a heavy-handed solution that is not practical for testing.

Another answer suggested removing your app's entry from /private/var/mobile/Library/RemoteNotification/Clients.plist, but this file does not exist on iOS5.

Is there a way to accomplish this on iOS5?

Community
  • 1
  • 1
Jeff W
  • 255
  • 4
  • 9

2 Answers2

5

I found a solution that works if your device is jailbroken:

  • Use an app like iFile to open the file /var/mobile/Library/SpringBoard/applicationstate.plist with a property list viewer
  • Find your app's bundle identifier and delete the key SBRemoteNotificationClient
  • Restart SpringBoard - either reboot the device, SSH to the device and run killall SpringBoard, or use the Respring app.

Next time you run your app, it will show the notification permission dialog once again.

I've tested this on iOS 5.1.1.

Jeff W
  • 255
  • 4
  • 9
  • It doesn't have to be jailbroken. You can download iExplorer and still change that. – gmogames Nov 26 '12 at 01:49
  • Even with iExplorer, you can't access root filesystem unless the device is jailbroken. See the "How do I access the real root?" question at http://www.macroplant.com/faq.php?program=iExplorer+(Mac) – Jeff W Nov 27 '12 at 22:30
  • This is a good solution, but unfortunately it's somewhat incomplete, at least on iOS 6.1. On first install/run of a new app, the ```- application:didRegisterForRemoteNotificationsWithDeviceToken:``` callback doesn't get triggered until the user hits "Allow". On later runs, even with the dialog successfully reset using the method you describe, the callback happens immediately after calling ```registerForRemoteNotificationTypes:```. :( – patr1ck Feb 21 '13 at 06:09
  • patr1ck: I haven't verified on iOS 6.1, but last I checked the callback *always* happens immediately after calling registerForRemoteNotificationTypes. The [documentation](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didRegisterForRemoteNotificationsWithDeviceToken:) doesn't say anything about waiting for the dialog. – Jeff W Feb 22 '13 at 02:39
  • 2
    In iOS7, this file is in this location: /private/var/mobile/Library/BackBoard/applicationState.plist – Mark Edington Mar 12 '14 at 20:19
  • There we have it. It's easier to develop iPhone apps using a jailbroken iPhone. Come on, Apple should include a legitimate way of doing this! – sudo May 15 '14 at 01:36
  • Is it possible to do the opposite and force the simulator to act like it is already registered for notifications? – zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Oct 04 '14 at 01:41
0

Provided your code paths for iOS 5 and iOS 6 aren't too different, the easiest option is probably to just test that specific behaviour on iOS 6 — the callbacks you get on iOS 5 should be similar enough for it not to be an issue.

Alternatively, change the app's bundle ID. Slightly tedious (in the past I've needed to restart Xcode for it to notice that change in bundle ID), and you'll need a wildcard provisioning profile handy.

tc.
  • 33,468
  • 5
  • 78
  • 96
  • 1
    What do you mean test it on iOS 6? I haven't verified, but I don't think any of the options I tried will work on iOS 6 any more than they do on iOS 5. – Jeff W Oct 26 '12 at 20:07