[英]ios 8 MapKit location will not start
從ios 8開始,我無法在調試器中啟動mapkit。 我在Mac OS X 10.9.5上使用XCode版本6.1(6A1052d)。 是的,我已閱讀並搜索了一些建議,但無法正常工作。
我在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斯德哥爾摩
嘗試移動
mapView.showsUserLocation = YES;
到-locationManager:didChangeAuthorizationStatus:
您可以在此處檢查> = kCLAuthorizationStatusAuthorized的狀態,並在那里設置showsUserLocation
:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status >= kCLAuthorizationStatusAuthorized) {
self.mapView.showsUserLocation = YES;
}
}
宣布
CLLocationManager *locationManager
在您的.h文件中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.