iOS 8 个 CLLocationManagerDelegate 方法从未被调用

iOS 8 CLLocationManagerDelegate methods are never called

//View did Load Method- LocationManager is allocated and have included the CLLocationManagerDelegate in .h File

-ViewDidLoad{
self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    self.locationManager.distanceFilter=kCLDistanceFilterNone;
    [self.locationManager requestWhenInUseAuthorization];
    [self.locationManager startMonitoringSignificantLocationChanges];
    [self.locationManager startUpdatingLocation];

}
// Location Manager Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"%@", [locations lastObject]);
}

在 plist 中你必须添加 2 个条目

  1. NSLocationWhenInUseUsageDescription
  2. NSLocationAlwaysUsageDescription

将两者的字符串设为 "Location is required to find out where you are" 或任何内容

self.locationManager = [[CLLocationManager alloc]init];

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];

if (authorizationStatus == kCLAuthorizationStatusAuthorized ||
    authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
    authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
    NSLog(@"You are authorized");

}

self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];

希望对您有所帮助