ios 关闭一次后如何返回“允许推送通知”对话框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21571978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get back "Allow Push Notifications" dialog after it was dismissed once?
提问by Schultz9999
I am building an app that is heavily relies on APN. Upon the very first start of my app, iOS asks if this app is allowed to use APN (as a result of registerForRemoteNotificationTypes:
call). However once dismissed, this dialog is never popping up back. I have to manually go to Settings->Notifications->MyApp
to enable/disable things there. So is there a way to avoid this hustle and actually experience what user will experience upon the very first start every time I start my app in debug mode?
我正在构建一个严重依赖 APN 的应用程序。在我的应用程序第一次启动时,iOS 会询问是否允许此应用程序使用 APN(作为registerForRemoteNotificationTypes:
调用的结果)。然而,一旦被解雇,这个对话框就永远不会弹出。我必须手动去Settings->Notifications->MyApp
启用/禁用那里的东西。那么有没有办法避免这种喧嚣,并在每次我在调试模式下启动我的应用程序时实际体验用户在第一次启动时的体验?
回答by Eran
Here's how Apple sayyou can do it:
以下是Apple 说您可以做到的方式:
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.
在 iOS 上重置推送通知权限警报
启用推送的应用程序首次注册推送通知时,iOS 会询问用户是否希望接收该应用程序的通知。一旦用户对此警报做出响应,除非设备恢复或应用程序已卸载至少一天,否则它不会再次出现。
如果您想模拟应用程序的首次运行,您可以将应用程序卸载一天。您可以按照以下步骤实现后者,而无需等待一天:
从设备中删除您的应用程序。
完全关闭设备并重新打开。
前往“设置”>“通用”>“日期与时间”,然后将日期提前一天或更长时间。
再次完全关闭设备并重新打开。
回答by Albert Renshaw
Since time is money and the other methods take FOREVER—just change your bundle ID over and over while debugging, each time notifications will get queried fresh. Once you are satisfied with code return to original bundle ID.
由于时间就是金钱,而其他方法需要永远——只需在调试时一遍又一遍地更改您的包 ID,每次通知都会得到新的查询。一旦您对代码感到满意,就返回原始捆绑 ID。
Key Notes from comments below:
以下评论中的要点说明:
- Temporarily turn off all other Capabilities (like IAP) to get around needing to change the provisioning profile.
- 暂时关闭所有其他功能(如 IAP)以避免需要更改配置文件。
回答by Genki
On iOS 9.x, you can get the prompt every time you delete the app and reinstall it. This is true for both AppStore production downloads and adhoc mode. The device token will be unique each time.
在 iOS 9.x 上,每次删除应用程序并重新安装它时,您都会收到提示。这适用于 AppStore 生产下载和临时模式。设备令牌每次都是唯一的。
@chengsam verified this is true in iOS 10 as well. @WongWray verified this is true in iOS 11 as well.
@chengsam 在 iOS 10 中也证实了这一点。@WongWray 在 iOS 11 中也证实了这一点。
回答by David Aanis
On IOS10 i can now get the prompt again by just deleting the app.
在 IOS10 上,我现在只需删除应用程序即可再次获得提示。
回答by Woodstock
Currently their is no programmaticway to prompt a user to re-accept Push Notificaitons after they have already decided to say no.
目前,他们没有以编程方式提示用户在他们已经决定拒绝后重新接受推送通知。
You should simply check if you have been granted access, and if not display a view reminding the user to manually give permission in the privacy settings in order to enable push notification features of your application.
您应该简单地检查您是否已被授予访问权限,如果没有显示一个视图,提醒用户在隐私设置中手动授予权限,以便启用应用程序的推送通知功能。
回答by buckleyJohnson
My problem was not registering for UserNotificationSettings. This allowed the APN to work but not the background sound or badge.
我的问题不是注册 UserNotificationSettings。这允许 APN 工作,但不允许背景声音或徽章。
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
回答by mofojed
If you're just testing that the Push Notifications prompt appears correctly, use the simulator. All you need to do is uninstall the app and reinstall, and the prompt will appear again when you try to register for push notifications.
如果您只是测试推送通知提示是否正确显示,请使用模拟器。您需要做的就是卸载应用程序并重新安装,当您尝试注册推送通知时,提示会再次出现。