CLLocationManager 权限
CLLocationManager permissions
我正在处理位置权限问题,接下来是问题:
用户从隐私中关闭了位置服务并安装了该应用程序。我有一行代码要求启用定位服务: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];
}
只有在授权状态为 NotDetermined 时才能iOS请求用户权限。
如果用户拒绝了您的应用,让他们再次收到提示的唯一方法是卸载该应用,或在设备上重置隐私。
最简单的方法是为警报控制器提供 link 设置,以便他们可以自行打开它。
.
你的代码毫无意义。你有这个:
if (something) {
}
if (somethingelse) {
[self.locationManager requestWhenInUseAuthorization];
}
所以你有一个 if
是空的,另一个 if
总是 运行而不管第一个 if
做什么。也许您打算对第二个条件使用 else if
?
(请记住,如您所知,除非状态为 NotDetermined,否则调用 requestWhenInUseAuthorization
毫无意义。)
我正在处理位置权限问题,接下来是问题:
用户从隐私中关闭了位置服务并安装了该应用程序。我有一行代码要求启用定位服务: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];
}
只有在授权状态为 NotDetermined 时才能iOS请求用户权限。
如果用户拒绝了您的应用,让他们再次收到提示的唯一方法是卸载该应用,或在设备上重置隐私。
最简单的方法是为警报控制器提供 link 设置,以便他们可以自行打开它。
你的代码毫无意义。你有这个:
if (something) {
}
if (somethingelse) {
[self.locationManager requestWhenInUseAuthorization];
}
所以你有一个 if
是空的,另一个 if
总是 运行而不管第一个 if
做什么。也许您打算对第二个条件使用 else if
?
(请记住,如您所知,除非状态为 NotDetermined,否则调用 requestWhenInUseAuthorization
毫无意义。)