0
votes

I have an app that is tracking a User's location. I have much experience with this and have requested when in use Authorization and have added the key to my P-List, however I still receive this error:

"Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first."

The location Manager that I am using is not in the ViewController but in another class.

2

2 Answers

0
votes

It doesn't matter where those methods are called from, so you could call either of those methods either from your app delegate's applicationDidFinishLaunching method (these authorization methods run asynchronously) or in the viewDidAppear method of your very first view controller.

0
votes

check the [CLLocationManager authorizationStatus] before setting mapView.showsUserLocation = YES or startUpdatingLocation Make sure that your CLLocation variable is strong.

(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

    if (status == kCLAuthorizationStatusAuthorizedWhenInUse) //or kCLAuthorizationStatusAuthorizedAlways
   {
        self.mapView.showsUserLocation = YES;
locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startUpdatingLocation()
    }

You must use anyone of the authorization

self.locationManager.requestWhenInUseAuthorization(); or self.locationManager.requestAlwaysAuthorization();

Anyhow the warning will not come for the second time after the user accept the permission