0

I created UISwitch to enable/disable push notifications that should be supported by both iOS 7 and iOS 8. I am trying to figure out how to get this working in iOS 8. Can't figure out what to fill in the following blank:

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{

    .......... fill in here...for iOS 8.........................
}

else
{
    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    BOOL turnedOffFromWithinNotificaitonCenter = (types == UIRemoteNotificationTypeNone);

    if (turnedOffFromWithinNotificaitonCenter){
        _remindersSwitch.on = FALSE;
    }
    else{
        _remindersSwitch.on = TRUE;
    }
}

Any suggestion appreciated. Thanks.

hightech
  • 3,742
  • 3
  • 25
  • 36

1 Answers1

0

Notifications now use a UIUserNotificationSettings object to encapsulate this sort of information. The types are still contained within there. As such, the 'blank' would be:

UIUserNotificationSettings* currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
UIUserNotificationType enabledTypes = currentSettings.types;

BOOL turnedOffFromWithinNotificaitonCenter = ((enabledTypes & UIUserNotificationTypeNone) == UIUserNotificationTypeNone);

if (turnedOffFromWithinNotificaitonCenter){
    _remindersSwitch.on = FALSE;
}
else{
    _remindersSwitch.on = TRUE;
}
WDUK
  • 18,870
  • 3
  • 64
  • 72
  • thanks! what about this [application unregisterForRemoteNotifications]; ? – hightech Aug 22 '14 at 18:06
  • `unregisterForRemoteNotifications` is still valid, that hasn't been deprecated – WDUK Aug 26 '14 at 09:47
  • In fairness, Apple does say "You should call this method in rare circumstances only". You shouldn't need to call it all the time. – WDUK Aug 27 '14 at 09:56