开发者

CLLocation ask again for permission

开发者 https://www.devze.com 2023-01-26 13:17 出处:网络
Currently my开发者_运维百科 application asks only once for permission to use the current location. If the user doesn\'t allow, he isn\'t ask again unless he resets location warning in the general sett

Currently my开发者_运维百科 application asks only once for permission to use the current location. If the user doesn't allow, he isn't ask again unless he resets location warning in the general settings. I would like to give the user a chance from within the app to grant this permission later. In other words, the dialog should appear again if he presses a certain button. Is this possible?

Thanks for your advice.


[CLLocationManager locationServicesEnabled] just tells you if the locations services are enable on the device.

according to this document.

[CLLocationManager authorizationStatus]

will return one of these

typedef enum {
   kCLAuthorizationStatusNotDetermined = 0,
   kCLAuthorizationStatusRestricted,
   kCLAuthorizationStatusDenied,
   kCLAuthorizationStatusAuthorized
} CLAuthorizationStatus;

if the result is kCLAuthorizationStatusDenied your could tell the user to allow the usage of the location services by sending him to the settings.app


New Answer: Now in iOS 8 you CAN programatically open the device settings app:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];

If you are supporting earlier iOS versions and want to make sure this can be handled, do this:

if (&UIApplicationOpenSettingsURLString != NULL) {
   NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
   [[UIApplication sharedApplication] openURL:url];
}
else {
  //Earlier iOS version
}

Old Answer: There is no way I know of to force the native popup to appear (and allow the user to jump to the settings page).

You can use the following method to determine if the user has allowed location services for your app: CLLocationManager:

+(CLAuthorizationStatus)authorizationStatus

You can also find out if location services are globally enabled at the device level or not, too: CLLocationManager:

+(BOOL)locationServicesEnabled
0

精彩评论

暂无评论...
验证码 换一张
取 消