【问题标题】:Prompt for general iOS Location Services提示一般 iOS 定位服务
【发布时间】: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


【解决方案1】:

在您的 info.plist 文件中,您需要包含以下行之一:

如果一直在使用,则将此条目添加到info.plist

NSLocationAlwaysUsageDescription

与该条目关联的字符串应该是您希望显示的消息:`您是否希望在此应用未使用时也启用持续位置监控?"

...或...

您可以发送NSLocationWhenInUseUsageDescription 和类似以下内容的消息:“您希望仅在使用此应用时启用位置监控吗?”

Here's documentation covering this topic

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-08
    • 2012-08-12
    相关资源
    最近更新 更多