iOS 8 MKMapView用户位置请求失败

我一直试图移动我的iOS7应用程序与MKMapview支持iOS8。 但是,我无法得到用户分享他们的位置正常工作的新要求。 我在故事板上创build了我的MKMapView,并在iOS7上完成了代理设置并完美工作。 这是我已经添加到支持iOS8位置共享:

myMapView.h

#import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import <CoreLocation/CoreLocation.h> @interface myMapView : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> @property (strong, nonatomic) IBOutlet MKMapView *mapView; @property (strong, nonatomic) CLLocationManager *locationManager; 

myMapView.m

 //Code omitted #define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) //Code omitted - (void)viewDidLoad { [super viewDidLoad]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; if(IS_OS_8_OR_LATER) { //[self.locationManager requestWhenInUseAuthorization]; [self.locationManager requestAlwaysAuthorization]; [self.locationManager startUpdatingLocation]; } [self.mapView setShowsUserLocation:YES]; [self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES]; } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, 0.0 } }; region.center.latitude = self.locationManager.location.coordinate.latitude; region.center.longitude = self.locationManager.location.coordinate.longitude; region.span.latitudeDelta = 0.0187f; region.span.longitudeDelta = 0.0137f; [self.mapView setRegion:region animated:YES]; _initialPosition = NO; } 

另外,我NSLocationAlwaysUsageDescription设置了NSLocationAlwaysUsageDescription键和它的值,当提示用户共享它们的位置时,显示正确的消息。

不幸的是,委托函数-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations永远不会被调用。 尽pipe每次viewController被加载时,都会调用[self.locationManager startUpdatingLocation] ,但委托似乎没有回应。 有没有问题,我如何设置委托或有什么我在这里失踪?

更新:这似乎也是我的gpx文件没有在启动时被调用。 我清除并重新加载我的位置文件,甚至更改为默认位置,但没有find位置: Domain=kCLErrorDomain Code=0

更新2:这是从实际上用户请求成功设置的SS,但无论我刷新多less,都无法获取/更新位置。 应用程序隐私级别:位置共享总是http://barisaltop.com/location.png

谢谢!

前几天我有同样的问题。 解决scheme是将string密钥NSLocationAlwaysUsageDescription (用于[CLLocationManager requestAlwaysAuthorization] )或NSLocationWhenInUseUsageDescription (用于[CLLocationManager requestWhenInUseAuthorization] )添加到您的Supporting Files / Info.plist

您也可以通过右键单击>打开为>源代码来编辑Info.Plist 源代码,并添加以下行:

 <!-- for requestAlwaysAuthorization --> <key>NSLocationAlwaysUsageDescription</key> <string>Explain for what are you using the user location</string> <!-- for requestWhenInUseAuthorization --> <key>NSLocationWhenInUseUsageDescription</key> <string>Explain for what are you using the user location</string> 

希望这可以帮助。

最后,我成功地在模拟器上运行我的gpx文件。 看来在第一次安装Xcode 6之后,可能会有一个导致gpx文件模拟的bug。 这是我如何克服这个问题:

  1. 我已经从模拟器中删除了我的应用程序
  2. 在应用程序 – >function启用背景模式 – >位置更新
  3. 运行应用程序,并让它安装在模拟器上
  4. 允许访问,我可以通过GPXfind用户
  5. 之后,我禁用了位置更新。

我不知道为什么,但是这对我来说是个诡计。