IsRegisteredForRemoteNotifications always returns no

I got a popup, I accepted it, I see it in notifications, and it's on, but this code always returns no, and I can't understand why

UIApplication *application = [UIApplication sharedApplication]; BOOL enabled; // Try to use the newer isRegisteredForRemoteNotifications otherwise use the enabledRemoteNotificationTypes. if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) { enabled = [application isRegisteredForRemoteNotifications]; } else { UIRemoteNotificationType types = [application enabledRemoteNotificationTypes]; enabled = types & UIRemoteNotificationTypeAlert; } if (enabled){ NSLog(@"is registered"); }else{ NSLog(@"is not registered"); } 
+6
source share
4 answers

I think this could happen:

  • isRegisteredForRemoteNotifications will always return NO in simulators.
  • RegisterForRemoteNotifications error.
+9
source

I was struggling with the same problem, it worked for me.

 BOOL enabled = NO; UIUserNotificationSettings *notificationSettings = [SharedApplication currentUserNotificationSettings]; enabled = notificationSettings.types < 4; 
+1
source

According to Apple's documentation, isRegisteredForRemoteNotifications returns NO if registration failed, failed, or was rejected by the user. 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.

Check out the Apple documentation for a better description.

Return value

YES , if the application is registered for remote notifications and received its device token or NO , if registration was not completed, 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 connection issues. The value returned by this method takes into account user preferences for receiving remote notifications.

+1
source

I think the simulator will always return no , try running your code on a real device and see if the behavior continues

0
source

Source: https://habr.com/ru/post/981780/


All Articles