iOS 判断是否开启定位
+ (BOOL)isLocationServiceOpen {
if ([ CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
return NO;
} else
return YES;
}
iOS 判断是否允许消息通知
- ios10以及之后版本
+ (void)isMessageNotificationServiceOpenBlock:(void (^)(BOOL))block{
if ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0) {
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
NSLog(@"setting = %@",settings);
if(settings.authorizationStatus == UNAuthorizationStatusAuthorized){
if (block) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"没有打开通知权限" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", @"取消", nil];
alertView.delegate = self;
[alertView show];
block(true);
}
} else {
if (block) {
block(false);
}
}
}];
// return true;
} else if (SYSTEM_VERSION_GREATER_THAN(@"8.0") {
if (block) {
block([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]);
}
} else {
if (block) {
block(UIRemoteNotificationTypeNone != [[UIApplication sharedApplication] enabledRemoteNotificationTypes]);
}
}
}
- ios10之前版本
+ (BOOL)isMessageNotificationServiceOpen {
if (SYSTEM_VERSION_GREATER_THAN(@"8.0")) {
BOOL pushEnabled;
// 设置里的通知总开关是否打开
BOOL settingEnabled = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
// 设置里的通知各子项是否都打开
BOOL subsettingEnabled = [[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone;pushEnabled = settingEnabled && subsettingEnabled;
return pushEnabled;
} 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"]];
}