Geolocation 显示用户的位置Xcode6/IOS8

Geolocation 显示用户的位置Xcode6/IOS8,geolocation,ios8,xcode6,core-location,Geolocation,Ios8,Xcode6,Core Location,我已经从Xcode 5升级到Xcode 6,现在我的应用程序不再工作了,我很自豪它能在IOS7下工作。我有一个著名的调试输出: 尝试在不提示位置授权的情况下启动MapKit位置更新。必须首先调用-[CLLocationManager RequestWhenUseAuthorization]或-[CLLocationManager requestAlwaysAuthorization] 当然,我一直在谷歌上搜索这条消息以找到解决方案,但似乎没有任何效果。所以我想征求你的意见 这是我的头文件: #i

我已经从Xcode 5升级到Xcode 6,现在我的应用程序不再工作了,我很自豪它能在IOS7下工作。我有一个著名的调试输出:

尝试在不提示位置授权的情况下启动MapKit位置更新。必须首先调用-[CLLocationManager RequestWhenUseAuthorization]或-[CLLocationManager requestAlwaysAuthorization]

当然,我一直在谷歌上搜索这条消息以找到解决方案,但似乎没有任何效果。所以我想征求你的意见

这是我的头文件:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "MapPoint.h"

#define kGOOGLE_API_KEY @"my google api"
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

@interface XYZViewController : UIViewController <MKMapViewDelegate,       CLLocationManagerDelegate>

{
CLLocationManager *locationManager;
CLLocationCoordinate2D currentCentre;
int currenDist;
BOOL firstLaunch;
}

@property (weak, nonatomic) IBOutlet MKMapView *mapView;

@end

您需要按照错误描述告诉您的操作,并在未使用授权或requestAlwaysAuthorization时添加对Request的调用。这件事以前已经讲过了

所需的更改可能如下所示:

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.

  //Make this controller the delegate for the map view.
  self.mapView.delegate = self;


  //Instantiate a location object.
  locationManager = [[CLLocationManager alloc] init];

  //Make this controller the delegate for the location manager.
  [locationManager setDelegate:self];

  //Set some parameters for the location object.
  [locationManager setDistanceFilter:kCLDistanceFilterNone];
  [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

  // Request use on iOS 8
  if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
    // Ensure that you can view your own location in the map view.
    [self.mapView setShowsUserLocation:YES];
  } else {
    [locationManager requestWhenInUseAuthorization];
  }

  firstLaunch=YES;
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
  if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {
    // Ensure that you can view your own location in the map view.
    [self.mapView setShowsUserLocation:YES];
  }
}
上面的代码按照苹果公司推荐的方式进行版本检查,你也可以进行功能检查,这比较干净,但根据我自己的经验,有时会导致问题

棘手的部分是你需要在app Info.plist中提供你的使用说明。否则,UIAlert将不会出现,您也不会被授予权限。转到xcode中的项目/目标设置,单击“信息”选项卡。单击+按钮。对于键,输入nsLocationWhenUsageDescription,该值应为描述如何使用用户位置的字符串。您还可以在“支持文件”下打开“Info.plist”文件


我怀疑这就是为什么它还没有对您起作用。

我在以前的尝试中添加了带有字符串值的键,但没有起作用。不管怎么说,你在这么短的时间内给出的答案对我帮助很大,现在我的项目开始工作了!非常感谢你。顺致敬意,
- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.

  //Make this controller the delegate for the map view.
  self.mapView.delegate = self;


  //Instantiate a location object.
  locationManager = [[CLLocationManager alloc] init];

  //Make this controller the delegate for the location manager.
  [locationManager setDelegate:self];

  //Set some parameters for the location object.
  [locationManager setDistanceFilter:kCLDistanceFilterNone];
  [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

  // Request use on iOS 8
  if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
    // Ensure that you can view your own location in the map view.
    [self.mapView setShowsUserLocation:YES];
  } else {
    [locationManager requestWhenInUseAuthorization];
  }

  firstLaunch=YES;
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
  if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {
    // Ensure that you can view your own location in the map view.
    [self.mapView setShowsUserLocation:YES];
  }
}