2013-04-18 26 views
0

我正在尝试使用CLLocationManage获取设备当前位置。我设置我的方法来获取点击按钮的位置。我可以成功获取位置,但当我收到带有两个按钮“不允许”和“Ok”的消息“APPNAME想要使用您当前的位置?”时,我点击“不允许”。然后,每当我点击按钮,我不能再次获取该alertview来获取当前位置,所以我无法获得位置。那么,当我点击我的按钮来获取位置时,是否有可能每次获得alertview?每次获取当前位置的警报

+0

可能的重复[CoreLocation每次都会询问权限](http://stackoverflow.com/questions/10736735/corelocation-make-asking-permission-everytime) – 2013-04-19 00:11:00

回答

3

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

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

+0

它的工作..非常感谢你:) – user7388 2013-04-18 06:01:03

+0

幸福,你得到它的工作...干杯:) – 2013-04-18 06:04:59

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"); 
    } 
} 
1

选择的答案是正确的,为用户。

不过,如果你是一个程序员,你希望用户能够与警示通知,你应该叫

[singleton.locationManager startUpdatingLocation]; 

这将自动弹出时的位置服务被禁用警报每次我觉得你的时间希望。

一个常见的错误是检查位置更新是否已启用,如果不是,则不要打扰调用startUpdatingLocation。

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