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

释放双眼,带上耳机,听听看~!

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文章

iOS APP 代码优化 启动优化(优化总结)

2019-12-30 7:18:15

iOS文章

iOS 使用fastlane自动打包

2019-12-30 9:12:15

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索