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

Was it helpful?

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.

Documentation here.

OTHER TIPS

I created a component for ease of use permissions on iOS.

Available in my Github:

enter image description here

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 ...
    }];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top