IOS:如何在用户拒绝时获取CLLocationManager警报
问题描述:
如何在用户拒绝时打开我的应用程序时启用CLLocationManager
警报。任何人都可以告诉如何?IOS:如何在用户拒绝时获取CLLocationManager警报
locationManager = [CLLocationManager new];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
我需要再次打开我的应用程序后显示此警报。
答
位置权限警报只显示一次。如果用户拒绝了您的应用的权限,那么他们必须在设置>隐私>位置服务中启用位置服务。有关更多信息,请参阅Apple的Understanding Location Services。
在您的代码中,您应该检查+[CLLocationManager authorizationStatus]
(documentation)的值 - 如果状态为kCLAuthorizationStatusDenied
,则可以提示用户在“设置”中重新启用位置服务。
答
如果用户拒绝此对话框,您CLLocationManagerDelegate
的-locationManager:didFailWithError:
回调将得到一个NSError
有:
- 域:kCLErrorDomain
- 代码:kCLErrorDenied
您可以妥善处理的错误。
它只显示一次,你可以做它显示一个新的alertview告诉用户去设置应用程序,并给予您的应用程序的权限的唯一一件事 – jcesarmobile
@jcesar让你的答案 – AnthonyBlake