Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if a user allows the app to use their location

The first time the app tries to get the users location they are prompted with "Would like to use your current location" and they can hit Don't allow or ok. Is there any way to find out if the user has hit ok or don't allow? I'm trying to have the MKMapView show the users current location but I would like to take different actions based on the users selection.

Normally you would think there would be a delegate to get this information but there doesn't seem to be.

Thanks in advance for your help.

like image 981
jmurphy Avatar asked Dec 15 '09 04:12

jmurphy


1 Answers

Your first call to get the user's location will fail with an error which tells you the user has denied location services. Your CLLocationManagerDelegate method didFailWithError will be called, as below. (The constants are defined in CLError.h)

- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
{
    switch([anError code])
    {
    case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying
    break;

    case kCLErrorDenied: // CL access has been denied (eg, user declined location use)
    message = @"Sorry, flook has to know your location in order to work. You'll be able to see some cards but not find them nearby";
    break;

    case kCLErrorNetwork: // general, network-related error
    message = @"Flook can't find you - please check your network connection or that you are not in airplane mode";
    }
}
like image 169
Jane Sales Avatar answered Sep 17 '22 07:09

Jane Sales