重置应用程序的推送通知设置
我正在开发一个带有推送通知的应用程序。为了检查所有可能的用户交互方式,我想在用户拒绝在第一次启动期间为我的应用程序启用推送通知时测试我的应用程序。
但是,该对话框(由 registerForRemoteNotificationTypes
启动)每个应用仅出现一次。如何重置我的应用程序的 iPhone 操作系统内存。删除应用程序并重新安装没有帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
我同意 micmdk.. 我有一个带有推送通知的开发环境设置,需要一种方法来重置我的手机,使其看起来像初始安装......只有这些精确的步骤对我有用......需要两次重新启动设备:
来自 APPLE TECH DOC:
在 iOS 上重置推送通知权限警报
当支持推送的应用程序第一次注册推送通知时,iOS 会询问用户是否希望接收该应用程序的通知。用户响应此警报后,除非设备恢复或应用程序已卸载至少一天,否则不会再次显示。
如果您想模拟应用程序的首次运行,您可以将应用程序卸载一天。您可以按照以下步骤实现后者,而无需实际等待一天:
从设备中删除您的应用。
完全关闭设备,然后重新打开。
转到“设置”>一般>日期和时间时间并将日期提前一天或更长时间。
再次完全关闭设备,然后重新打开。
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:
Delete your app from the device.
Turn the device off completely and turn it back on.
Go to Settings > General > Date & Time and set the date ahead a day or more.
Turn the device off completely again and turn it back on.
正如 ianolito 所说,设置日期应该有效:
我注意到在我的设备(iPhone 4、iOS 6.1.2)上将系统时钟设置提前一天甚至几天对我来说不起作用。因此,我将日期提前一个月,然后它起作用了,我的应用程序再次显示通知提示。
希望这对任何人都有帮助,这可能有点头疼!
As ianolito said, setting the date should work:
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!
我过去曾想过这个问题,并得出结论:这实际上并不是我的代码的有效测试用例。我认为您的应用程序代码实际上无法区分某人第一次拒绝通知或后来从 iPhone 通知设置中禁用它。确实,用户体验有所不同,但这隐藏在对 registerForRemoteNotificationTypes 的调用中。
调用 unregisterForRemoteNotifications 不会完全从通知设置中删除该应用程序 - 尽管它确实删除了该应用程序的设置内容。因此,这仍然不会导致下次应用程序运行时再次向用户显示对话框(至少在我当前正在测试的 v3.1.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.
与接受的答案中提到的技术说明相同(TN2265 - 故障排除推送通知) 此后已更新为适用于 iOS 5 及更高版本的解决方案。
简而言之:每次创建备份并从中恢复。
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.
Apple 技术说明还描述了您可以恢复设备以重置推送通知对话框。
它并没有说您还可以使用设备本身(iOS 5.x)上的“常规 -> 重置 -> 擦除所有内容和设置”选项。
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).
我最近在反应本机应用程序中遇到了类似的问题。 iPhone OS 版本是 13.1 我卸载了该应用程序并尝试安装该应用程序,发现没有提示位置和通知权限。
在检查设置时,我可以看到我的应用程序已启用位置(从以前的安装),但是没有针对通知的相应条目尝试卸载并重新启动而不设置时间,它不起作用。顺便说一句,我也尝试下载 Appstore 应用程序,仍然有同样的行为。
设置设备时间后问题才得到解决。
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.
除了ianolito的回答。
我一年前下载的一个应用程序也有同样的问题,最初拒绝推送通知。现在想要恢复推送通知,这些步骤在 iOS 7 beta 上对我有用。不确定哪个点准确地触发了它。
感谢上帝,我不必“删除所有内容和设置”。也许它会对某人有所帮助。
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.
Thank god I did not have to "Erase All Content And Settings". Maybe it will help someone.
经过几个小时的搜索,上面的建议没有成功,这对于 3.x+ 来说就像一个魅力
After hours of searching, and no luck with the suggestions above, this worked like to a charm for 3.x+
技术说明 TN2265:推送通知故障排除
更新: 正如下面的评论所述,此解决方案自 iOS 5.1 起停止工作。我鼓励向 Apple 提交错误,以便他们可以更新其文档。当前的解决方案似乎是重置设备的内容和设置。
更新:技术说明已更新,添加了自 iOS 7 起可正常运行的新步骤。
自 iOS 9 起更新
只需删除并重新安装应用程序即可将通知状态重置为
notDetermined
(这意味着将出现提示)。感谢以下 Gomfucius 的回答:
https://stackoverflow.com/a/33247900/704803
Technical Note TN2265: Troubleshooting Push Notifications
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.
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
另一个仅用于测试的解决方案是简单地更改您的包 ID。只是完成后不要忘记将其更改回来!
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!
在 iOS 9.0.2 上,每次删除应用程序并重新安装时,我都会收到“注册推送通知警报”。对于 AppStore 生产下载和临时模式都是如此。
更新:已确认这适用于 iOS 9.x
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
正如已经指出的,在 iOS5 更新版本中,重置设备上应用程序的通知状态的方法已更改。
这在 iOS6 上适用于我:
但这只会使初始再次出现提示 - 它不会删除任何其他推送状态相关的内容。
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:
However this will only make the initial prompt appear again - it will not remove any other push state related stuff.
清单:
/private/var/mobile/Library/RemoteNotification/Clients.plist
...包含已注册的推送通知客户端。删除应用程序的条目将导致提示重新出现
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
以编程方式进行似乎每次都对我有用。
我有一个未注释的以下行的构建:
每次我想从 PN 取消注册时都会运行它。您可能必须从最近使用的列表中显式结束该应用程序,并使用“设置”应用程序中的“通知中心”才能正确使用。
此外,要求用户注册 PN 的 UI 提示可能不会显示。不确定是否在最近的 iOS 版本中被禁用。
Doing it programmatically seems to work for me everytime.
I have a build with the following line uncommented:
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.