下面的代码不能再工作了,我们能做什么
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"prefs:root=LOCATION_SERVICES"]];
以下适用于转到设置 → 您的应用程序 → 位置 但我想访问转到设置 → 隐私 → 定位服务
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
我遇到了和下面问题一样的问题
Open Settings app from another app programmatically in iPhone
最佳答案
如果用户不打开定位服务,我会使用此代码
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error {
if ([[error domain] isEqualToString: kCLErrorDomain] && [error code] == kCLErrorDenied) {
// The user denied your app access to location information.
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"This app does not have access to Location" message:@"You can enable access in Settings" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Settings", nil];
alert.delegate = self;
[alert show];
}
NSLog(@"%@", error.description);
}
并在此代码中 UIAlertView
中处理 Settings
按钮:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"buttonIndex:%d",buttonIndex);
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}
关于ios - 我如何提示用户打开位置服务,即转到设置→隐私→位置服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31428242/