每次都获得当前位置的警报

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

当您点击“不允许”button时,您的应用程序的位置权限受到限制。

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

添加这个答案,以便更有效地处理这种情况。

没有办法强制再次强制当前的位置权限对话框,但是你可以做的就是使用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"); } } 

所选的答案对用户来说是正确的。

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

 [singleton.locationManager startUpdatingLocation]; 

这会自动popup警报时,位置服务被禁用,每当我想你想。

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

如果是这样,那么警报就不会显示出来。