简体   繁体   English

检测用户对“允许推送”通知对话框的响应

[英]detect user response to the Allow Push notification dialog

Is there any way to detect what user choose when promoted with the "allow push notification" dialog? 有没有办法通过“允许推送通知”对话框检测用户选择的内容?

I want to catch what user choose at the moment he tap one of the dialog buttons ("Allow" or "Don't Allow") 我想抓住用户在点击其中一个对话框按钮时选择的内容(“允许”或“不允许”)
any why I can do this? 为什么我能做到这一点?

I'm afraid not. 恐怕不是。 While you can determine whether notifications are enabled (using UIApplication's isRegisteredForRemoteNotifications method), this does not tell you why notifications are not registered when they aren't. 虽然你可以决定通知是否被允许(使用的UIApplication的isRegisteredForRemoteNotifications方法),这并不能告诉你为什么通知未注册的时候都没有。

It could be for any of the following reasons: 可能出于以下任何原因:

• The user has never been prompted for them. •从未提示用户使用它们。

• The user has specifically declined them.* •用户明确拒绝了他们。*

• The user approved them at some point, but has since turned them off.* •用户在某个时候批准了它们,但此后又关闭了它们。*

It's unfortunate that Apple does not provide a means to detect a user declining push notification registration when prompted. 不幸的是,Apple在提示时没有提供检测用户拒绝推送通知注册的方法。 I suspect this is a conscious design decision intended to make it less likely for developers to harangue users. 我怀疑这是一个有意识的设计决定,旨在使开发人员不太可能讨好用户。

I hope this helps. 我希望这有帮助。

(* ...you could infer which of the second and third options applies by storing a persistent flag upon the first registration, but this doesn't seem to be what you're asking for...) (* ...您可以通过在首次注册时存储持久性标志来推断第二个和第三个选项中的哪个适用,但这似乎不是您要求的......)

There is no direct way of doing this, but I've implemented a workaround: APNPermisionRequest . 没有直接的方法,但我实施了一个解决方法: APNPermisionRequest

The interesting part here is to add an observer for UIApplicationDidBecomeActiveNotification and then show the request. 这里有趣的部分是为UIApplicationDidBecomeActiveNotification添加一个观察者,然后显示请求。 After the notification is fired (ie. the request was answered), you can check for the status using [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] . 在通知被触发后(即请求被回答),您可以使用[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]检查状态。

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

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