I have set my app to initially request location as soon as it loads but the first time the app is used the dialog box pops that asks permission from the user appears for a brief second then disappears as the view finished loading (or something). This all happens too quick for the user to say “yep, that’s ok”. Where should I put the following code to make the location permission popup appear the first time the user loads the app?
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
CLLocation *location = [[CLLocation alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager setPurpose:@"A fun way to record where you've answered the questions and how you did at each location."];
[locationManager startUpdatingLocation];
location = [locationManager location];
[locationManager stopUpdatingLocation];
Thank you,
Bren
There are many places where you can put this code. Basically, it needs to be after you have finished to load the user interface.
It can be in your AppDelegate, as long as it’s after the
[self.window makeKeyAndVisible]call.It can also be in the method
viewDidAppear:of your first viewController. If you choose this option, keep in mind thatviewDidAppear:can be called many times.