CLLocation 管理器不返回位置

CLLocation manager not returning location

我正在尝试在我的 viewDidLoad 方法中使用此代码获取当前位置:

//init the location manager
locationManager = [[CLLocationManager alloc] init];    
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[locationManager startUpdatingLocation];

我有我的委托方法:

//if it fails to get the location
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    self.currentLocation = newLocation;

}

我的 UIViewController 符合 CLLocationManagerDelegate 但是我没有 activity,没有 NSLog 或错误。我已经在设备上进行了测试。有人可以告诉我这里可能出了什么问题吗?

确保您遵循文档中的指南

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

尤其是“UIRequiredDeviceCapabilities”键在您的 Info.plist 中。