+ (BOOL)isLocationServiceOpen { if ([ CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) { return NO; } else return YES; }
+ (BOOL)isMessageNotificationServiceOpen { if (SYSTEM_VERSION_GREATER_THAN(@"8.0")) { return [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; } else { return UIRemoteNotificationTypeNone != [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; } }
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"]]; }
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 是判斷版本的宏定義url
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)