How to check permission for userLocation
-
13-07-2021 - |
Question
Is there a way to check if the user gave permission or not to my App use his/her location coordinates? I'd like check this before he/she press a button to submit some info, and I'll only activate this button if user gave permission.
My app uses iOS 6.
Thanks
Solution
In your delegate of the CLLocationManager
instance, implement the
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
method. If this method is called with its error
parameter set to kCLErrorDenied
, then the user has not enabled using the location services. You can also implement the
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
method - when the status
parameter of this callback method is not kCLAuthorizationStatusDenied
, then the user has enabled your app to use his location.
OTHER TIPS
I created a component for ease of use permissions on iOS.
Available in my Github:
An example of use using block:
/*
User can be choose two enum type for request the location authorization:
- AuthorizeRequestTypeAlwaysAuthorization
- AuthorizeRequestTypeWhenInUseAuthorization
*/
[[IOSCheckPermissions globalInstance] checkPermissionAccessForLocation:self.locationManager
authorizeRequestType:AuthorizeRequestTypeWhenInUseAuthorization
successBlock:^{
// SUCCESS ...
} failureBlock:^{
// PERMISSION DENIED ...
}];