Когда я пытаюсь использовать карту в iOS 8, я становлюсь ниже ошибки.
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
Для этого я попробовал решение здесь, но все равно не повезло.
Ниже я это сделал.
Шаг 1. Войдите в Info.plist
NSLocationWhenInUseUsageDescription - This is test text
Шаг 2. Обновлено - (CLLocationCoordinate2D) getLocation
-(CLLocationCoordinate2D) getLocation{
CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// this is change
if(IS_OS_8_OR_LATER) {
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}
Шаг 3. Префикс .pch
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
Шаг 4. Удалите приложение снова с помощью ниже в viewDidLoad.
CLLocationCoordinate2D theCoordinate;
theCoordinate = [self getLocation];
NSLog(@"ffffff===%f===%f", theCoordinate.latitude, theCoordinate.longitude);
Тем не менее я получаю вывод как
ffffff===0.000===0.000
Примечание:
Я получаю предупреждение, но это всего лишь половина секунд и исчезает, а затем я получаю сообщение как
CLLocationCoordinate2D theCoordinate;
theCoordinate = [self getLocation];
NSLog(@"ffffff===%f===%f", theCoordinate.latitude, theCoordinate.longitude);
Когда я перехожу в настройку, чтобы проверить статус для местоположения, ниже есть то, что у меня есть.
Любая идея, почему это происходит?