重置应用程序的推送通知设置

发布于 2024-08-24 15:05:55 字数 202 浏览 5 评论 0原文

我正在开发一个带有推送通知的应用程序。为了检查所有可能的用户交互方式,我想在用户拒绝在第一次启动期间为我的应用程序启用推送通知时测试我的应用程序。

但是,该对话框(由 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

风蛊 2024-08-31 15:05:56

我同意 micmdk.. 我有一个带有推送通知的开发环境设置,需要一种方法来重置我的手机,使其看起来像初始安装......只有这些精确的步骤对我有用......需要两次重新启动设备:

来自 APPLE TECH DOC:

在 iOS 上重置推送通知权限警报
当支持推送的应用程序第一次注册推送通知时,iOS 会询问用户是否希望接收该应用程序的通知。用户响应此警报后,除非设备恢复或应用程序已卸载至少一天,否则不会再次显示。

如果您想模拟应用程序的首次运行,您可以将应用程序卸载一天。您可以按照以下步骤实现后者,而无需实际等待一天:

  1. 从设备中删除您的应用。

  2. 完全关闭设备,然后重新打开。

  3. 转到“设置”>一般>日期和时间时间并将日期提前一天或更长时间。

  4. 再次完全关闭设备,然后重新打开。

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.

夏の忆 2024-08-31 15:05:56

正如 ianolito 所说,设置日期应该有效:

您可以通过将系统时钟向前设置一天或更长时间,完全关闭设备,然后重新打开设备来实现后者,而无需实际等待一天。

我注意到在我的设备(iPhone 4、iOS 6.1.2)上将系统时钟设置提前一天甚至几天对我来说不起作用。因此,我将日期提前一个月,然后它起作用了,我的应用程序再次显示通知提示。

希望这对任何人都有帮助,这可能有点头疼!

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!

眼眸里的快感 2024-08-31 15:05:56

我过去曾想过这个问题,并得出结论:这实际上并不是我的代码的有效测试用例。我认为您的应用程序代码实际上无法区分某人第一次拒绝通知或后来从 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.

送你一个梦 2024-08-31 15:05:56

与接受的答案中提到的技术说明相同(TN2265 - 故障排除推送通知) 此后已更新为适用于 iOS 5 及更高版本的解决方案。

简而言之:每次创建备份并从中恢复。

在 iOS 5 及更高版本上,通过从备份恢复设备来重置推送通知权限警报 (r. 11450187)。以下是有效执行此操作的步骤:

  1. 使用 Xcode Organizer 在设备上安装您的应用程序。关键是首次安装应用程序而不运行它。
  2. 使用 iTunes 备份设备。
  3. 运行应用程序。将显示推送通知权限警报。
  4. 当您想要重置推送通知权限警报时,请从您在第一步中创建的备份恢复设备。

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.
初见终念 2024-08-31 15:05:56

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).

月下客 2024-08-31 15:05:56

我最近在反应本机应用程序中遇到了类似的问题。 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.

泪痕残 2024-08-31 15:05:56

除了ianolito的回答。

我一年前下载的一个应用程序也有同样的问题,最初拒绝推送通知。现在想要恢复推送通知,这些步骤在 iOS 7 beta 上对我有用。不确定哪个点准确地触发了它。

  • 关闭并删除该应用程序。
  • 转到 iCloud 设置并从 iCloud 中删除该应用程序。在启用了应用程序 iCloud 备份的所有其他设备上执行此操作。停用并删除后进行新备份。该应用程序不应再列在备份下。 (这可能就是 ianolito 描述的 Apple 技术说明在 iOS 5 中停止工作的原因,因为 iOS 5 中引入了 iCloud,并且许多应用程序启用了 iCloud 备份。)
  • 转到您的时间设置并将时间设置为提前 1 个月以上。
  • 关闭 iPhone(不重置)。
  • 稍等一下,重新打开并重新下载应用程序。
  • 启动应用程序,我再次看到该对话框。
  • 再次启用应用程序备份,因为它仍处于停用状态。修正时间。

感谢上帝,我不必“删除所有内容和设置”。也许它会对某人有所帮助。

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.

宣告ˉ结束 2024-08-31 15:05:56

经过几个小时的搜索,上面的建议没有成功,这对于 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
        }

    }

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
        }

    }
み格子的夏天 2024-08-31 15:05:55

技术说明 TN2265:推送通知故障排除

第一次启用推送的应用程序
注册推送通知,iOS
询问用户是否希望接收
该应用程序的通知。一旦
用户已对此警报做出响应
除非设备再次出现,否则不会再次出现
已恢复或应用程序已
卸载至少一天。

如果你想模拟第一次
运行您的应用程序,您可以离开该应用程序
卸载了一天。 你可以实现
后者实际上无需等待
通过设置系统时钟来设置日期
前进一天或更长时间,转动
设备完全关闭,然后关闭
设备重新打开。

更新: 正如下面的评论所述,此解决方案自 iOS 5.1 起停止工作。我鼓励向 Apple 提交错误,以便他们可以更新其文档。当前的解决方案似乎是重置设备的内容和设置。

更新:技术说明已更新,添加了自 iOS 7 起可正常运行的新步骤。

  1. 从设备中删除您的应用。
  2. 完全关闭设备,然后重新打开。
  3. 转到“设置”>一般>日期和时间计时并将日期提前一天或更长时间。
  4. 再次完全关闭设备,然后重新打开。

自 iOS 9 起更新

只需删除并重新安装应用程序即可将通知状态重置为 notDetermined(这意味着将出现提示)。

感谢以下 Gomfucius 的回答:
https://stackoverflow.com/a/33247900/704803

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

孤独陪着我 2024-08-31 15:05:55

另一个仅用于测试的解决方案是简单地更改您的包 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!

_蜘蛛 2024-08-31 15:05:55

在 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

装纯掩盖桑 2024-08-31 15:05:55

正如已经指出的,在 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:

  • 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.

莫相离 2024-08-31 15:05:55

清单:
/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

节枝 2024-08-31 15:05:55

以编程方式进行似乎每次都对我有用。
我有一个未注释的以下行的构建:

 [[UIApplication sharedApplication] unregisterForRemoteNotifications];

每次我想从 PN 取消注册时都会运行它。您可能必须从最近使用的列表中显式结束该应用程序,并使用“设置”应用程序中的“通知中心”才能正确使用。

此外,要求用户注册 PN 的 UI 提示可能不会显示。不确定是否在最近的 iOS 版本中被禁用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文