- (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];
}];
}
}

本文介绍了一个iOS应用中用于检查设备定位服务是否启用及授权状态的方法,并在未授权时引导用户前往设置页面进行授权设置的实现细节。
49

被折叠的 条评论
为什么被折叠?



