iOS应用内跳转系统推送设置页

判断用户是否打开了推送

#pragma mark - 是否开启APP推送
/**是否开启推送*/
+ (BOOL)isSwitchAppNotification {
    if (IOS_VERSION >= 10.0) {
        __block BOOL result = NO;
        //异步线程中操作是否完成
        __block BOOL inThreadOperationComplete = NO;
        [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
            if (settings.authorizationStatus == UNAuthorizationStatusDenied) {
                result = NO;
            }else if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
                result = NO;
            }else if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
                result = YES;
            }else {
                result = NO;
            }
            inThreadOperationComplete = YES;
        }];
        
        while (!inThreadOperationComplete) {
            [NSThread sleepForTimeInterval:0];
        }
        return result;
    }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    else if (IOS_VERSION >= 8.0)
    {
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        if (UIUserNotificationTypeNone != setting.types) {
            return YES;
        }else {
            return NO;
        }
        
    }else
    {
        UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        if(UIRemoteNotificationTypeNone != type) {
            return YES;
        }else {
            return NO;
        }
    }
#pragma clang diagnostic pop
}

然后如果用户没有打开推送按钮
跳转到应用相关设置页面

    if (switch.on) {
        if (IOS_VERSION >= 10.0) {
            NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            [[UIApplication sharedApplication]openURL:url options:@{} completionHandler:^(BOOL success) {
                
            }];
        }else{
            //[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]] 应用标识
            NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"prefs:root=%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]]];
            [[UIApplication sharedApplication]openURL:url];
        }
    }

参考资料

iOS应用内跳转到指定系统设置页

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,038评论 3 119
  • 1、分段 两个回车2、换行 两个空格 + 回车3、标题 #~###### 井号的个数表示几级标题...
    sunny4handsome阅读 1,599评论 0 0
  • “我等你,用世上唯一的眼,来把我心头的希望复活,或把这沉重的噩梦捅破。” 一 天将欲雨 憔悴的人类冲出重围 走入黄...
    水槛阅读 3,097评论 9 8
  • 【0417,今日反思】 001、今天事情没做好,真的尽力了吗?还可以怎样呢?留下时间做重要但不紧急的事。 002、...
    小苏Amy阅读 721评论 2 2
  • 总是那么多的对爱与希望的幻想,不愿舍弃,总在为自己的懒惰与不作为找着接口。我开始深刻反省,关于我自己一直放不下的对...
    爱撸铁的程序猿阅读 1,436评论 0 0