iOS 8 beta – 位置管理器未注册用户位置

自从新的iOS 8测试版发布以来,我无法成功获取用户的位置.在更新到iOS 8之前,我没有任何问题,但现在它总是返回0.000000作为当前纬度和经度.这只是新版本中的一个错误吗?我的代码如下:
//from the .h file
@interface MasterViewController : PFQueryTableViewController<CLLocationManagerDelegate,UITextFieldDelegate,UISearchBarDelegate,UISearchdisplayDelegate> {

}
@property (nonatomic,strong) CLLocationManager *locationManager;

//from the .m file
@synthesize locationManager = _locationManager;

- (void)viewDidLoad {
  [super viewDidLoad];
  [self.locationManager startUpdatingLocation];
}


- (CLLocationManager *)locationManager {
   if (_locationManager != nil) {
       return _locationManager;
   }

   _locationManager = [[CLLocationManager alloc] init];
   _locationManager.delegate = self;
   _locationManager.desiredAccuracy = kCLLocationAccuracyBest;

   return _locationManager;
}

 - (void)locationManager:(CLLocationManager *)manager
        didUpdatetoLocation:(CLLocation *)newLocation
               fromLocation:(CLLocation *)oldLocation { 
}

 - (void)locationManager:(CLLocationManager *)manager
                    didFailWithError:(NSError *)error {
}

UPDATE
这个问题已得到解答(Location Services not working in iOS 8).对于仍在努力解决这个问题的人来说,为了保持与iOS 7的向后兼容性,我使用了以下代码

if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])    { }

解决方法

如您的更新/评论中所述,iOS8要求您在Info.plist中使用requestAlwaysAuthorization或requestWhenInUseAuthorization以及新的NSLocationAlwaysUsageDescription或NSLocationWhenInUseUsageDescription键.

但是你的代码还有其他错误

- (void)locationManager:(CLLocationManager *)manager
        didUpdatetoLocation:(CLLocation *)newLocation
               fromLocation:(CLLocation *)oldLocation

它已在iOS6中弃用,您现在应该使用这个新的委托方法

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

然后,您可以使用以下内容获取最新位置:

CLLocation *newLocation = [locations lastObject];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...