0

我正在尝试使用CLLocationManage. 我将我的方法设置为在按钮单击时获取位置。我可以成功获取位置,但是当我收到带有消息“ APPNAME 想使用您当前的位置? ”的警报视图时,带有两个按钮,“不允许”和“确定”。然后我点击“不允许”。然后,每当我单击按钮时,我就无法再次获取该警报视图以获取当前位置,因此我无法获取该位置。那么每次单击按钮获取位置时是否可以获取警报视图?

4

3 回答 3

3

当您单击警报上的“不允许”按钮时,您的应用程序的位置权限将受到限制。

您可以导航到手机中的设置>隐私>位置服务,在那里您可以看到服务已为您的应用程序关闭。您可以打开它以授予权限

于 2013-04-18T05:52:17.503 回答
1

添加此答案,以便您可以更有效地处理该场景。

没有办法再次强制当前位置权限对话框,但您可以做的是捕获其用户已拒绝在您的应用程序中使用位置的状态,使用CLLocationManagerDelegate,

- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)error
{
    switch([error code])
    {
    case kCLErrorDenied: // Location access denied
    NSLog(@"Sorry, this app needs to access your current location... ");
    UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"Sorry, this 
    app needs to access your current location. You can navigate to settings in your 
    phone > privacy >location services, over there you can see services are off for you 
    application. You can turn it on to give permissions"  
    delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
    //show the alert view
    [myAlert show];
    break;

    case kCLErrorNetwork: // received n/w error
    NSLog(@"Network error occurred");
    }
}
于 2013-04-18T06:07:13.013 回答
1

对于用户来说,选择的答案是正确的。

但是,如果您是程序员并且希望用户收到警报通知,则应致电

[singleton.locationManager startUpdatingLocation];

每次我如您所愿时,当位置服务被禁用时,这将自动弹出警报。

一个常见的错误是检查是否启用了位置更新,并且在未启用时不要打扰调用 startUpdatingLocation。

如果是这种情况,则不会显示警报。

于 2013-04-21T21:54:36.907 回答