Reputation: 111
Since ios 8 I cannot get the mapkit to start in the debugger. I'm using XCode Version 6.1 (6A1052d) on Mac OS X 10.9.5. And yes I've read and googled several suggestions but I can't get it to work.
I have added these lines in my myproject-info.plist;
</array>
<key>NSLocationUsageDescription</key>
<string>I need location</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>I need location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>I need location</string>
</dict>
This is how I try to initialice LocationManager in my first view viewDidLoad method;
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
Later, in another controller i programatically add a mapkit view like this;
mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
[self.view addSubview:mapView];
[mapView setDelegate:self];
mapView.showsUserLocation = YES;
But I always get this in the output console;
2014-11-22 19:14:36.777 vind4r[1019:16660] Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
Any ideas someone?
Kind regards, Jan Gifvars Stockholm
Upvotes: 0
Views: 197
Reputation: 1568
Try to move
mapView.showsUserLocation = YES;
To the
-locationManager:didChangeAuthorizationStatus:
There you can check status for >= kCLAuthorizationStatusAuthorized and set showsUserLocation
there:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status >= kCLAuthorizationStatusAuthorized) {
self.mapView.showsUserLocation = YES;
}
}
Upvotes: 0