Determine on Iphone If User Has Enabled Push Notifications

Swift ios check if remote push notifications are enabled in ios9 and ios10

Updated answer after iOS 10 is using UNUserNotificationCenter .

First you need to import UserNotifications then

let current = UNUserNotificationCenter.current()
current.getNotificationSettings(completionHandler: { permission in
switch permission.authorizationStatus {
case .authorized:
print("User granted permission for notification")
case .denied:
print("User denied notification permission")
case .notDetermined:
print("Notification permission haven't been asked yet")
case .provisional:
// @available(iOS 12.0, *)
print("The application is authorized to post non-interruptive user notifications.")
case .ephemeral:
// @available(iOS 14.0, *)
print("The application is temporarily authorized to post notifications. Only available to app clips.")
@unknown default:
print("Unknow Status")

this code will work till iOS 9, for iOS 10 use the above code snippet.

let isRegisteredForRemoteNotifications = UIApplication.shared.isRegisteredForRemoteNotifications
if isRegisteredForRemoteNotifications {
// User is registered for notification
} else {
// Show alert user is not registered for notification

Determine on iPhone if user has enabled push notifications

Call enabledRemoteNotificationsTypes and check the mask.

For example:

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone)
// blah blah blah

iOS8 and above:

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]

ios check if user has disabled push notifications

Check below code it will help you:

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

if (types == UIRemoteNotificationTypeNone) {
// send info to the server that this user has disallowed push notifications

Cordova: clean way to check if user has enabled push notifications

You could use the isRemoteNotificationsEnabled() method of cordova-diagnostic-plugin:

console.log("Push notifications are " + (isEnabled ? "enabled" : "disabled"));
}, function(error){
console.error("An error occurred: "+error);

iOS push notification: how to detect if the user tapped on notification when the app is in background?

OK I finally figured out.

In the target settings ➝ Capabilities tab ➝ Background Modes, if you check "Remote Notifications", application:didReceiveRemoteNotification: will get triggered as soon as notification arrives (as long as the app is in the background), and in that case there is no way to tell whether the user will tap on the notification.

If you uncheck that box, application:didReceiveRemoteNotification: will be triggered only when you tap on the notification.

It's a little strange that checking this box will change how one of the app delegate methods behaves. It would be nicer if that box is checked, Apple uses two different delegate methods for notification receive and notification tap. I think most of the developers always want to know if a notification is tapped on or not.

Hopefully this will be helpful for anyone else who run into this issue. Apple also didn't document it clearly here so it took me a while to figure out.

iOS Sample Image 16

Find out if user has accepted to receive Push Notifications?

You can get the current notification settings with currentUserNotificationSettings:

let notificationSettings = UIApplication.sharedApplication().currentUserNotificationSettings()
print("Notification types allowed by user is: \(notificationSettings.types).")

If the user has disabled notifications, the types will be None.

Get Push Notification enabled/disabled event from settings app ios?

You can poll for changes with this call. You can call this on your viewDidAppear when you return to your app. You can also call it from your appDelegate on your applicationDidBecomeActive to check someone's status.

 UNUserNotificationCenter.current().getNotificationSettings { settings in


Related Topics

Leave a reply