【问题标题】:iPhone - display the "location need to be available" dialogiPhone - 显示“位置需要可用”对话框
【发布时间】:2011-11-09 19:51:56
【问题描述】:

在设备(Iphone 4、IOS 4.2.1)上进行测试,当您使用 MapKit / CLLocationManager 时,会出现一个标准对话框,要求用户启用位置设置,并建议一个按钮进入该设置。

如果你点击“确定”,那么这个对话框似乎再也不会出现了?

如何以编程方式使其再次出现以帮助用户通过该对话框进入正确的设置视图?

【问题讨论】:

    标签: iphone ios cocoa-touch settings core-location


    【解决方案1】:

    嗯,不可能以编程方式调出标准对话框,要求用户允许您的应用使用位置服务。这一切都由 iOS 完成。

    但是,您始终可以尝试在 CLLocationManager 实例上通过 startUpdatingLocation 方法开始位置更新。如果定位服务被禁用,您将收到委托通知有关错误情况的通知,然后您可以调出对话框,要求用户进入设置并为您的应用启用定位服务...请参阅下面的过滤代码kCLErrorDenied

    #pragma mark - CLLocationManagerDelegate
    - (void)locationManager:(CLLocationManager *)inManager didFailWithError:(NSError *)inError{
        if (inError.code ==  kCLErrorDenied) {
            NSLog(@"Location manager denied access - kCLErrorDenied");
            // your code to show UIAlertView telling user to re-enable location services
            // for your app so they can benefit from extra functionality offered by app
        }
    }
    

    请注意,您无法通过应用程序中的 URL 方案启动设置应用程序。

    更新:从iOS5.1开始,您可以使用以下方法。

    更新:从 iOS5 开始,您可以从应用程序启动设置:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多