从ios 8开始,我无法在调试器中启动mapkit。我正在使用XCode版本6.1(6A1052d) 在Mac OS X 10.9.5上。是的,我已阅读并搜索了几条建议,但我无法让它发挥作用。
我在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>
这是我尝试在我的第一个视图viewDidLoad方法中初始化LocationManager的方法;
CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
稍后,在另一个控制器中,我以编程方式添加这样的mapkit视图;
mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
[self.view addSubview:mapView];
[mapView setDelegate:self];
mapView.showsUserLocation = YES;
但我总是在输出控制台中得到它;
2014-11-22 19:14:36.777 vind4r [1019:16660]尝试在不提示位置授权的情况下启动MapKit位置更新。必须先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization]。
有人有什么想法吗?
亲切的问候, Jan Gifvars 斯德哥尔摩
答案 0 :(得分:0)
尝试移动
mapView.showsUserLocation = YES;
到了
-locationManager:didChangeAuthorizationStatus:
在那里你可以检查&gt; = kCLAuthorizationStatusAuthorized的状态并在那里设置showsUserLocation
:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status >= kCLAuthorizationStatusAuthorized) {
self.mapView.showsUserLocation = YES;
}
}
答案 1 :(得分:0)
声明
CLLocationManager *locationManager
你的.h文件中的