I'm attempting to use implement an instance of MKMapView
, use CoreLocation
to track the users location, and then zoom in to where they are.
I only want to track the user's location when I'm in the foreground. Since my app is targeted for iOS8, I have a plist entry for the key NSLocationWhenInUseUsageDescription
.
When I run the app for the first time, the app appropriately asks if it can access my location. After I click 'Allow', I then receive the following warning from Xcode:
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
...which is a bit confusing, as I am in fact calling requestWhenInUseAuthorization
, as can be seen in my code below:
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
@property(nonatomic, retain) CLLocationManager *locationManager;
@end
@implementation MapView
- (void)viewDidLoad {
[super viewDidLoad];
[self locationManager];
[self updateLocation];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
self.locationManager = nil;
}
- (CLLocationManager *)locationManager {
//We only want to get the location when the app is in the foreground
[_locationManager requestWhenInUseAuthorization];
if (!_locationManager) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
return _locationManager;
}
- (void)updateLocation {
_mapView.userTrackingMode = YES;
[self.locationManager startUpdatingLocation];
}
Does anyone have any insight into why this warning would be occurring?