iOS 判斷是否開(kāi)啟定位
+ (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:@"沒(méi)有打開(kāi)通知權(quán)限" 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;
// 設(shè)置里的通知總開(kāi)關(guān)是否打開(kāi)
BOOL settingEnabled = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
// 設(shè)置里的通知各子項(xiàng)是否都打開(kāi)
BOOL subsettingEnabled = [[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone;pushEnabled = settingEnabled && subsettingEnabled;
return pushEnabled;
} else {
return UIRemoteNotificationTypeNone != [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
}
}
iOS 跳轉(zhuǎn)系統(tǒng)設(shè)置打開(kāi)定位頁(yè)面
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 跳轉(zhuǎn)系統(tǒng)設(shè)置打開(kāi)消息頁(yè)面
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"]];
}