Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isRegisteredForRemoteNotifications always returns no

I got the pop up, i have accepted, i see it in the notifications and it is turned on but this code always returns no and i cant seem to find out 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");
}
like image 697
marshy101 Avatar asked Jan 30 '15 18:01

marshy101


2 Answers

I think what makes it happen might be:

  1. isRegisteredForRemoteNotifications will always return NO in simulators.
  2. registerForRemoteNotifications fails.
like image 55
yingshanliu Avatar answered Oct 18 '22 17:10

yingshanliu


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

BOOL enabled = NO;
UIUserNotificationSettings *notificationSettings = [SharedApplication currentUserNotificationSettings];
enabled = notificationSettings.types < 4;
like image 1
luisfcofv Avatar answered Oct 18 '22 17:10

luisfcofv