【发布时间】:2014-12-08 23:54:14
【问题描述】:
当我尝试在 iOS 8 中使用地图时,出现以下错误。
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
For this I tried solution from here,但还是没有运气。
以下是我所做的。
步骤 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. Prefix.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);
当我进入设置检查位置状态时,以下是我所拥有的。
知道为什么会这样吗?
我正在 iPad 2 iOS 8.0 和模拟器 iOS 8.0 上进行测试
【问题讨论】:
标签: objective-c ios8 mapkit cllocationmanager cllocation