Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining if user has denied CoreLocation permission

Is it possible to determine programmatically that a user has denied permission to use their location?

Secondly, if a user has denied permission, is it possible to re-prompt the user?

like image 952
James Avatar asked Dec 28 '11 21:12

James


People also ask

How to get location Permission in swift?

By using location services and CLLocationManager you can request location permissions, check authorization status, get user location updates to personalize your app experience in Swift.

How do I ask for permission again iOS?

The OS will only ever prompt the user once. If they deny permission, that's it. What you can do is direct the user to the Settings for your app by passing UIApplicationOpenSettingsURLString to UIApplication 's openURL: method. From there, they can re-enable location services if they wish.


2 Answers

You can determine your authorization status using the authorizationStatus class method on CLLocationManager. This returns a CLAuthorizationStatus which is defined as:

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

The system will prompt the user to authorize your application if the authorization status is undetermined when you attempt to start the location manager.

Additionally, you can check the locationServicesEnabled class method to determine if location is enabled system wide.

like image 58
Mark Adams Avatar answered Oct 01 '22 17:10

Mark Adams


Additionally - If locationServicesEnabled returns NO and you attempt to start location services anyway, the system will prompt the user to confirm whether location services should be reenabled.

like image 21
Dennis Mathews Avatar answered Oct 03 '22 17:10

Dennis Mathews