2014-11-22 49 views
0

由于ios 8我无法让mapkit在调试器中启动。我在Mac OS X 10.9.5上使用XCode V6.1(6A1052d) 。是的,我已经阅读并搜索了一些建议,但我无法实现它的工作。ios 8 MapKit位置不会启动

我在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> 

这是我如何尝试在我的第一个view 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]。

任何想法的人?

亲切的问候, 扬Gifvars 斯德哥尔摩

回答

0

尝试移动

mapView.showsUserLocation = YES; 

-locationManager:didChangeAuthorizationStatus:

在那里,你可以检查状态为> = kCLAuthorizationStatusAuthorized并设置showsUserLocation有:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { 
    if (status >= kCLAuthorizationStatusAuthorized) { 
     self.mapView.showsUserLocation = YES; 
    } 
} 
+0

谢谢,我已经特里树的建议。现在几乎在那里,即我可以看到询问允许/不允许的对话框。但是,只要我的控制器从viewDidLoad方法返回并查看呈现Hhhmm,对话框就消失了,为什么不是对话框模式或什么?我从来没有结束...... didChangeAuthorizationStatus:方法。 – 2014-11-23 09:50:23

+0

对不起,我搞砸了一个当地声明的locationmanager。感谢您的时间和帮助! – 2014-11-23 09:55:07

0

声明

CLLocationManager *locationManager 

在.h文件中