iOS - 要求在初始拒绝后启用推送通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9029039/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:31:54  来源:igfitidea点击:

iOS - Ask to enable push notifications after initial decline

iosnotificationspushapple-push-notifications

提问by Joel

I would like to know if it's possible to force the "XXXXX would like to send you push notifications" popup from within an app, after an initial decline. The use case is as follows:

我想知道是否可以在最初拒绝后从应用程序中强制弹出“XXXXX 想向您发送推送通知”。用例如下:

  • The user installs the app, gets the alert about push notifications, and declines because they don't know/trust the app yet.

  • They use the app and proactively request within the app to be alerted when something happens (say for example something they want to buy is sold out so they want to be alerted when it is back in stock).

  • So now the user has asked the app to notify them about something specific but has push notifications disabled at the operating system level.

  • So if the user requests an alert, but I detect that they declined alerts on first run, I need to notify them of this and have them turn push notifications on for the alert to work.

  • Ideally, I would like to force the "XXXX would like to send you push notifications alert" at this point (a second time since they installed the app).

  • I guess plan b would be to show them my own message telling them they have to go into their system settings and turn it back on manually in order to receive the alert they want. This is far from ideal.

  • 用户安装该应用程序,收到有关推送通知的警报,然后拒绝,因为他们还不知道/信任该应用程序。

  • 他们使用应用程序并在应用程序内主动请求在发生某些事情时收到警报(例如,他们想购买的东西已售罄,因此他们希望在有货时收到警报)。

  • 所以现在用户已经要求应用程序通知他们一些特定的事情,但在操作系统级别禁用了推送通知。

  • 因此,如果用户请求警报,但我检测到他们在第一次运行时拒绝了警报,我需要通知他们这一点并让他们打开推送通知以使警报起作用。

  • 理想情况下,此时我想强制“XXXX 想向您发送推送通知警报”(自他们安装该应用程序以来第二次)。

  • 我想 b 计划是向他们展示我自己的消息,告诉他们必须进入系统设置并手动重新打开它才能收到他们想要的警报。这远非理想。

Any help would be appreciated. Thanks.

任何帮助,将不胜感激。谢谢。

回答by rob mayoff

You can't make iOS show the alert again. Here's a better approach:

您无法让 iOS 再次显示警报。这是一个更好的方法:

  1. Keep a flag in your NSUserDefaultsindicating whether you should register for push notifications at launch. By default the flag is false.
  2. When you launch, check the flag. If it's true, register immediately. Otherwise, don't register.
  3. The first time the user does something that would cause a push notification, register for push notifications and set the flag in NSUserDefaults.
  1. 在您的标志中保留一个标志,NSUserDefaults指示您是否应该在启动时注册推送通知。默认情况下,该标志为 false。
  2. 启动时,请检查标志。如果是真的,请立即注册。否则,不要注册。
  3. 用户第一次做一些会导致推送通知的事情时,注册推送通知并在 中设置标志NSUserDefaults

This way, when the user gets the push notifications alert, he has some idea why he's getting it, and might actually say yes.

这样,当用户收到推送通知警报时,他就会知道为什么会收到它,并且实际上可能会说是。

回答by Sailesh

I am also facing a similar kind of issue. After searching so much, I decided to do what you call Plan B. That is, show the user my own alert saying that push needs to be enabled for better experience, or something like that.

我也面临着类似的问题。搜索了这么多,我决定做你所谓的B计划。也就是说,向用户展示我自己的警报,说需要启用推送以获得更好的体验,或者类似的东西。

To check that required push types are enabled, use this method:

要检查是否启用了所需的推送类型,请使用以下方法:

- (UIRemoteNotificationType)enabledRemoteNotificationTypes

UIApplication reference

界面应用参考

I think that this is the clean solution. Consider a case where after accepting the request at first, the user turns off push, this thing will work even in that scenario.

我认为这是干净的解决方案。考虑这样一种情况,在最初接受请求后,用户关闭推送,即使在这种情况下,这件事也会起作用。

回答by Jeremy

The best way to do it would be to (if you're making a game) ask them a preemptive question (e.g. Do you want us to notify you when your crops are ready to be harvested? -Yes -No), and when they answer "yes", then fire the native iOS push popup. then you can layer in multiple questions along the user funnel, and you'll eventually catch them all.

最好的方法是(如果您正在制作游戏)问他们一个先发制人的问题(例如,您希望我们在您的庄稼可以收获时通知您吗?-是-否),以及何时回答“是”,然后触发本机 iOS 推送弹出窗口。然后你可以沿着用户漏斗将多个问题分层,最终你会发现所有问题。