Reputation: 2451
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?
Upvotes: 3
Views: 1198
Reputation: 14169
There is no direct way of doing this, but I've implemented a workaround: APNPermisionRequest.
The interesting part here is to add an observer for UIApplicationDidBecomeActiveNotification
and then show the request. After the notification is fired (ie. the request was answered), you can check for the status using [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]
.
Upvotes: 2
Reputation: 2139
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.
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. 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...)
Upvotes: 2