我正在处理位置的权限,接下来的问题是:用户从隐私中关闭位置服务,并安装了应用程序。我有一行要求启用位置服务的代码:if (![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied)...,它运行得很好。问题是,应用程序不要求允许应用程序使用位置,而是第二次询问。请求许可的代码:
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}注意:如果启用了位置服务,一切都可以正常工作,它第一次请求批准。
编辑:权限的完整代码:
-(void)setupPermissions
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if (![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
}
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
}发布于 2016-06-24 20:51:58
你的代码毫无意义。你有这个:
if (something) {
}
if (somethingelse) {
[self.locationManager requestWhenInUseAuthorization];
}因此,您有一个if是空的,另一个if总是运行,而不管第一个if做什么。也许您打算在第二个条件中使用else if?
(请记住,正如您已经知道的,调用requestWhenInUseAuthorization是没有意义的,除非状态是NotDetermined。)
发布于 2016-06-24 20:48:36
只有当授权状态为NotDetermined时,才能获得iOS请求用户权限。
如果用户拒绝了你的应用程序,你唯一能让他们再次被提示的方法就是卸载应用程序,或者重置设备上的隐私。
最简单的方法是为警报控制器提供一个指向设置的链接,这样他们就可以自己打开它。
https://stackoverflow.com/questions/38021727
复制相似问题