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.
+6
A:
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
}
}
Vladimir
2009-10-23 14:14:06
A:
Your controller should implement the CLLocationManagerDelegate
protocol. This defines two methods that you will need to implement:
– locationManager:didUpdateToLocation:fromLocation:
In this method you put your code to handle location updates.– 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.
Justin Gallagher
2009-10-23 14:30:34