Callback Method If User Declines Push Notification Prompt

Callback Method if user declines Push Notification Prompt?

In iOS 7, when the system's push notification prompt appears, the app becomes inactive and UIApplicationWillResignActiveNotification fires. Similarly when the user responds to the prompt (pressing either Yes or No), the app becomes active again and UIApplicationDidBecomeActiveNotification fires.

So you can listen for this notification, and then hide your loading screen.

Note: While the prompt is displayed, the Home button, Notification Center, and Control Center are disabled so they cannot trigger a false-positive UIApplicationDidBecomeActiveNotification. However if the user presses Lock button it will trigger UIApplicationDidBecomeActiveNotification.

How to know user tapped Don't allow in push notification

Unfortunately, we are not having accurate way to check whether user denies it or not.

But you can always check if it is given permission or not by this method.
UIApplication.shared.isRegisteredForRemoteNotifications which will just tell you if the application has actually registered with Apple's push servers and has received a device token:

Return Value YES

if the app is registered for remote notifications and
received its device token or NO if registration has not occurred, has
failed or has been denied by the user.

Swift: Action if the user accepted or rejected notifications

Note: Apple has since deprecated the answer I've given below. Please see @ergunkocak's answer

When the user has either granted or denied permissions, the callback method in the app delegate is application(_:didRegister:) which is the method you should use for taking specific actions based on the user's chosen permission settings. I suggest reading the documentation here.

Callback Method if user declines Push Notification Prompt?

In iOS 7, when the system's push notification prompt appears, the app becomes inactive and UIApplicationWillResignActiveNotification fires. Similarly when the user responds to the prompt (pressing either Yes or No), the app becomes active again and UIApplicationDidBecomeActiveNotification fires.

So you can listen for this notification, and then hide your loading screen.

Note: While the prompt is displayed, the Home button, Notification Center, and Control Center are disabled so they cannot trigger a false-positive UIApplicationDidBecomeActiveNotification. However if the user presses Lock button it will trigger UIApplicationDidBecomeActiveNotification.



Related Topics



Leave a reply



Submit