iOS判断推送通知是否开启
+ (BOOL)isUserNotificationEnable { // 判断用户是否允许接收通知
BOOL isEnable = NO;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0f) { // iOS版本 >=8.0 处理逻辑
UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
isEnable = (UIUserNotificationTypeNone == setting.types) ? NO : YES;
} else { // iOS版本 <8.0 处理逻辑
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
isEnable = (UIRemoteNotificationTypeNone == type) ? NO : YES;
}
return isEnable;
}
// 如果用户关闭了接收通知功能,该方法可以跳转到APP设置页面进行修改 iOS版本 >=8.0 处理逻辑
+ (void)goToAppSystemSetting {
UIApplication *application = [UIApplication sharedApplication];
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([application canOpenURL:url]) {
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[application openURL:url options:@{} completionHandler:nil];
} else {
[application openURL:url];
}
}
}
网友评论