美文网首页ios实用开发技巧单元测试
iOS判断推送通知是否开启

iOS判断推送通知是否开启

作者: RobinZhao | 来源:发表于2018-01-11 14:49 被阅读6466次

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

    相关文章

      网友评论

        本文标题:iOS判断推送通知是否开启

        本文链接:https://www.haomeiwen.com/subject/cfzznxtx.html