- (void)checkGPS
{
if ([CLLocationManager locationServicesEnabled]) {
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {
[self showAlertView:nil message:@"检测到当前定位服务已关闭,建议您开启定位服务" leftMenuTitle:@"取消" rightMenuTitle:@"去开启" alertResultBlock:^(AlertMenuIndex menuIndex) {
if (menuIndex == RightMenuIndex) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url] ) {
[[UIApplication sharedApplication] openURL:url];
}
}
}];
}
}
else {
[self showAlertView:nil message:@"检测到当前定位服务已关闭,建议您开启定位服务" leftMenuTitle:@"取消" rightMenuTitle:@"去开启" alertResultBlock:^(AlertMenuIndex menuIndex) {
NSURL*url=[NSURL URLWithString:@"Prefs:root=Privacy&path=LOCATION"];
// !!!关键代码!!!跟之前的写法也不一样了!!!
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:@selector(defaultWorkspace)] performSelector:@selector(openSensitiveURL:withOptions:) withObject:url withObject:nil];
}];
}
}