【发布时间】:2016-03-22 00:38:22
【问题描述】:
我想请用户启用通用位置服务(而不是应用特定的位置服务),如果作为一个整体,他们从未收到提示为应用启用它。
有没有办法在用户每次打开应用并被禁用时,提示用户将定位服务作为一个整体开启?
在其他线程中找到的代码,但它是特定于应用程序的,而不是一般的定位服务:
if(![CLLocationManager locationServicesEnabled]) {
NSLog(@"Location Services is OFF GLOBALLY");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString( @"Location Services", @"" ) message:NSLocalizedString( @"Please Set Location Services to On and Restart App\n\nSettings->Privacy->Location Services", @"" ) preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"OK", @"" ) style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
else if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
NSLog(@"Location Services is Never for App");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString( @"App Needs Location Services", @"" ) message:NSLocalizedString( @"Please Set Location Services to Always for App", @"" ) preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"Settings", @"" ) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
[alertController addAction:settingsAction];
[self presentViewController:alertController animated:YES completion:nil];
}
【问题讨论】:
-
为什么?您只需要应用特定的设置。
-
也许如果你分享你真正想要完成的事情,我们可以提供更好的帮助,因为如果你的应用不请求许可,没有理由提示用户完全启用定位服务使用它。
-
您可以检查
CLLocationManager.locationServicesEnabled的值,如果位置服务被禁用,则显示警报,但无法直接打开位置服务首选项。 -
我遇到了一群人,他们会打开定位服务片刻,然后将其关闭。这不是应用程序设置,而是全局设置。目前我的应用程序不提示通用位置服务是否关闭,它只会在它打开并且应用程序位置服务设置时提示。希望澄清一点。
-
用更多代码更新了原始帖子
标签: ios objective-c location-services