2009-10-23 55 views
1

当我在iPhone上安装应用程序时,它会在警报中询问当前位置的选项“不允许”和“确定”。我如何知道选择了哪个选项?我也只想显示这个选项一次。如果用户选择允许找到当前位置,我希望设备自动在后台获取位置。如何在提示核心位置时获得用户响应?

回答

7

如果用户拒绝访问位置信息服务,然后CLLocationManager委托方法didFailWithError:被调用:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ 
    if (error.code == kCLErrorDenied){ 
      // User denied access to location service  
    } 
} 
0

你的控制器应实现CLLocationManagerDelegate协议。这定义了两种方法,你将需要实现:

  1. – locationManager:didUpdateToLocation:fromLocation:
    在这种方法中,你把你的代码来处理位置更新。

  2. – locationManager:didFailWithError:
    在此方法中,您将代码处理拒绝您的请求或更新失败的用户。

一旦用户允许您使用他们的位置,他们将不会再被提示,除非他们退出应用程序。但是,每次启动应用程序时都无法阻止用户提示用户。