IsRegisteredForRemoteNotifications returns true, although I completely disabled it

if UIApplication.sharedApplication().isRegisteredForRemoteNotifications() == true { println("Yes, allowed") println(UIApplication.sharedApplication().isRegisteredForRemoteNotifications()) }else{ //don't do shit return } 

When I go to settings to completely turn off notifications and then return to the application, the application still prints true , allowed.

I can not get it to run false, even after uninstalling / reinstalling the application.

+8
ios objective-c swift
source share
3 answers

According to Apple's documentation, isRegisteredForRemoteNotifications will return NO if registration failed, failed, or the user was rejected. YES will be returned if the application registered for remote notifications and received a device token. Therefore, in response to your question NO it will not always return no, it will also return yes if your application has registered for remote notifications and it received its device token.

Return YES if the application is registered for remote notifications and received the token of its device, or NO if registration did not occur, failed or was rejected by the user.

Discussion This method only reflects the successful completion of the remote registration process, which begins when you call the registerForRemoteNotifications Method. This method does not reflect whether remote notifications are really available due to a connection problem. The value returned by this method accepts user preferences for remote notifications.

Above the point, return to the Apple document.

----- edited ----------

You can read application permissions using

 UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 

Then do any operation with the various types to see which ones are activated. You can also call unregisterForRemoteNotifications to turn off notifications.

----- Changes ------

- isRegisteredForRemoteNotifications

Gets a boolean value indicating whether the application is currently registered for remote notifications.

SWIFT declaration func isRegisteredForRemoteNotifications() -> Bool

OBJECTIVE-C - (BOOL)isRegisteredForRemoteNotifications

The return value is YES if the application is registered for remote notifications and received a token of its device or NO if registration did not occur, failed or was rejected by the user.

Discussion This method only reflects the successful completion of the remote registration process, which begins when you call the registerForRemoteNotifications Method. This method does not reflect whether remote notifications are really available due to a connection problem. The value returned by this method accepts user preferences for remote notifications.

+2
source share

I made an extension for Swift 3

 extension UIApplication { func remoteNotificationsEnabled() -> Bool { var notificationsEnabled = false if let userNotificationSettings = currentUserNotificationSettings { notificationsEnabled = userNotificationSettings.types.contains(.alert) } return notificationsEnabled } } 

And how to use it

 UIApplication.shared.remoteNotificationsEnabled() 
+9
source share

I have my notes on Push Notification at https://github.com/onmyway133/notes/issues/219

πŸš€ Scripts

These are the scenarios you can go through

isRegisteredForRemoteNotifications - UIApplication.shared.currentUserNotificationSettings

iOS 9.3.2 +

  • Do not start push request dialog: false - none
  • Enable push for the application when prompted for a request: true - warning, icon, sound
  • Disable push for application: true - none
  • Enable push, enable alert only: true - alert
  • Uninstall and install again (within 24 hours): false - none
  • Reject permission request: true - none
  • Repeated press after failure: true - warning, icon, sound

πŸ• API

In iOS 8+, the Push Notification API was split into registerForRemoteNotifications and registerUserNotificationSettings .

So when you call registerForRemoteNotifications

  • func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) is called
  • UIApplication.shared.isRegisteredForRemoteNotifications returns true

This means that the application receives a token-token and is ready to receive a push notification. Regardless of whether the OS supports the application prior to your application, it depends on the user notification settings , which the user switches to Settings

😎 Show me the code

To check if the push is enabled (means that the user can see the push message)

 static var isPushNotificationEnabled: Bool { guard let settings = UIApplication.shared.currentUserNotificationSettings else { return false } return UIApplication.shared.isRegisteredForRemoteNotifications && !settings.types.isEmpty } 
+3
source share

All Articles