在iOS 8中推送通知 - UISwitch

时间:2014-08-22 16:12:50

标签: ios objective-c push-notification ios8 xcode6

我创建了UISwitch以启用/禁用iOS 7和iOS 8都应该支持的推送通知。我试图弄清楚如何在iOS 8中使用它。无法确定要填写的内容以下空白:

    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;
    }
}

任何建议都表示赞赏。感谢。

1 个答案:

答案 0 :(得分:0)

通知现在使用UIUserNotificationSettings对象来封装此类信息。这些类型仍然包含在那里。因此,空白'将是:

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

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

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