简体   繁体   English

在iOS5中重置推送通知权限设置

[英]Reset push notification permission setting in ios5

I am developing an app that uses push notifications, and testing on a device with iOS 5.1.1. 我正在开发一个使用推送通知的应用程序,并在装有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. 该对话框是我第一次调用registerForRemoteNotificationTypes时出现的,但是即使从头开始重新安装该应用程序,也不会再次出现。 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. 之前的评论中也发布了相同的问题,但答案不适用于iOS 5或更高版本。

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. Apple的文档说要卸载该应用程序并弄乱时钟,以使其看起来好像该应用程序已被卸载了一天,但这在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. 另一个答案建议从/private/var/mobile/Library/RemoteNotification/Clients.plist中删除应用程序的条目,但是此文件在iOS5上不存在。

Is there a way to accomplish this on iOS5? 有没有办法在iOS5上做到这一点?

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 使用类似iFile的应用程序通过属性列表查看器打开文件/var/mobile/Library/SpringBoard/applicationstate.plist
  • Find your app's bundle identifier and delete the key SBRemoteNotificationClient 找到您应用的捆绑包标识符,然后删除密钥SBRemoteNotificationClient
  • Restart SpringBoard - either reboot the device, SSH to the device and run killall SpringBoard , or use the Respring app. 重新启动SpringBoard-重新启动设备,SSH到设备并运行killall SpringBoard ,或使用Respring应用程序。

Next time you run your app, it will show the notification permission dialog once again. 下次运行应用程序时,它将再次显示通知权限对话框。

I've tested this on iOS 5.1.1. 我已经在iOS 5.1.1上进行了测试。

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. 如果您的iOS 5和iOS 6的代码路径没有太大不同,最简单的选择可能就是测试iOS 6上的特定行为-您在iOS 5上获得的回调应该足够相似,这样才不会成为问题。

Alternatively, change the app's bundle ID. 或者,更改应用程序的捆绑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. 有点乏味(在过去,我需要重新启动Xcode来注意bundle ID的更改),并且您将需要一个通配符配置概要文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM