samiles
samiles

Reputation: 3900

Wait for user's response to allowing location services before running code

I have the following code to put in a call to location services (thereby raising the permission alert) and I wish to then run my code is they allow or show a view if they deny.

The code I have is the following, in my viewDidLoad method, but while this works the second time they load the app, after they've made their choice, neither option runs the first time round. Is there a way to make this code wait, essentially, so it will only run once they've made their choice?

CLLocationCoordinate2D coordinate = [self getLocation];
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)
{
    NSLog(@"location enabled");
    [self getDataFromJson];

} else {
    NSLog(@"location disabled");
    //show them a view telling them to allow location services
}

Upvotes: 1

Views: 1461

Answers (1)

FluffulousChimp
FluffulousChimp

Reputation: 9185

You should assign a delegate that conforms to the CLLocationManagerDelegate protocol and respond to changes in authorization status by implementing locationManager:didChangeAuthorizationStatus:

Upvotes: 4

Related Questions