美文网首页
iOS检测是否开启定位、是否允许消息通知

iOS检测是否开启定位、是否允许消息通知

作者: 爱上火烧的小毛驴 | 来源:发表于2016-11-03 10:26 被阅读854次

    iOS 判断是否开启定位

    + (BOOL)isLocationServiceOpen {
        if ([ CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
            return NO;
        } else
            return YES;
    }
    

    iOS 判断是否允许消息通知

    + (BOOL)isMessageNotificationServiceOpen {
        if (SYSTEM_VERSION_GREATER_THAN(@"8.0")) {
            return [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
        } else {
            return UIRemoteNotificationTypeNone != [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        }
    }
    

    iOS 跳转系统设置打开定位页面

    if (SYSTEM_VERSION_GREATER_THAN(@"8.0")) {
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication] canOpenURL:url]) {
                [[UIApplication sharedApplication] openURL:url];
            }
        } else {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
        }
    

    iOS 跳转系统设置打开消息页面

    if (SYSTEM_VERSION_GREATER_THAN(@"8.0")) {
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication] canOpenURL:url]) {
                [[UIApplication sharedApplication] openURL:url];
            }
        } else {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=NOTIFICATIONS_ID"]];
        }
    

    注:SYSTEM_VERSION_GREATER_THAN 是判断版本的宏定义

    #define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
    

    相关文章

      网友评论

          本文标题: iOS检测是否开启定位、是否允许消息通知

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