Question

in my app, i check if the user have enabled the Notification for my app, to enable the local notification, and i do it in this way:

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    if (types != UIRemoteNotificationTypeNone)
    {
       //All enabled
    } else {
       //not enabled
    }

but i have a problem with some users that in the iOS setting have all enabled, they send a screenshot to me and it's all correct, but the code goes in the else statement, as if it's all disabled. What is problem, anyone know how i can fix it?

Thanks

Was it helpful?

Solution

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
UIRemoteNotificationType allEnableType = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge ;
UIRemoteNotificationType disableType = UIRemoteNotificationTypeNone ;
if (types == allEnableType) {
    // all enable
} else if (types == disableType) {
    // all disable
} else {
    // some enable
}

Another remote notification type is available after ios 5.0 UIRemoteNotificationTypeNewsstandContentAvailability

OTHER TIPS

func isRegisteredForPushNotifications() -> Bool {
  if let notificationSettings = application.currentUserNotificationSettings() {
    return notificationSettings.types != UIUserNotificationType.None
  }
  return false
}

I used this in Swift 2, tested on iOS9.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top