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)
网友评论