Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 - enabledRemoteNotificationTypes return UIRemoteNotificationTypeNone but in Settings.app Alert,Badge and Sound are enabled

I have following code in view controller button action:

- (IBAction)requestPermissions:(id)sender
{
  DDLogInfo(@"Start permission requesting.");

  if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]){
    [[UIApplication sharedApplication] registerForRemoteNotifications];
  } else {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didBecomeActive:)
                                                 name:UIApplicationDidBecomeActiveNotification
                                               object:nil];
    [[UIApplication sharedApplication]
     registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
  }
}

After registration is finished didBecomeActive notification is posted and I'm making a check what user have done:

-(void)didBecomeActive:(NSNotification *)notification
{
   if([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone){
// if user decline 
}
} else {
 // if user accept
}

So my problem is: If user decline to receive push notifications and later decides to enable them (Settings->Notification center->My App), there is a surprise: 'Alert' ,'Badge' and 'Sound' are enabled in Settings, but app returns UIRemoteNotificationTypeNone.

Any ideas what is wrong?

Note: I know these methods are deprecated, so please don't tell me to use registerForRemoteNotifications: and UIUserNotificationSettings, it is already done.

like image 889
Foriger Avatar asked Jan 18 '16 13:01

Foriger


1 Answers

Well, possibly it returns a proper value after app restart, could you check that? I've found situations where iOS automatically kills your app when changing permissions in Settings while your app is in the background, f.e. Photos feed access; I suppose it's just a buggy implementation in iOS in this case, this wouldn't surprise me. I think I've hitted this situation you describe as well, and after finding it's returning invalid/old values until restart, I gave up and make the flow count with required restart.

Anyway, I don't think there's anything you could do about it.

like image 99
Michi Avatar answered Sep 25 '22 22:09

Michi