Question

When I install my application on the iPhone it asks for the current location with the options "Don't allow" and "Ok" in an alert. How do I find out which option was chosen? I also want to show this option only once. If the user chooses to allow their current location to be found, I want the device to automatically get the location in the background.

Was it helpful?

Solution

If user denied access to Location service then CLLocationManager delegate method didFailWithError: gets called:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    if (error.code ==  kCLErrorDenied){
            // User denied access to location service       
    }
}

OTHER TIPS

Your controller should implement the CLLocationManagerDelegate protocol. This defines two methods that you will need to implement:

  1. – locationManager:didUpdateToLocation:fromLocation:
    In this method you put your code to handle location updates.

  2. – locationManager:didFailWithError:
    In this method you put you code to handle the user denying your request, or updates failing.

Once the user allows you to use their location, they won't be prompted again unless they exit the app. There isn't a way to prevent the phone from prompting users each time they start up the app though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top