Reset push notification permission setting in ios5

2019-04-09 14:29发布

问题:

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?

回答1:

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.



回答2:

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.