iOS的8 CLLocationManagerDelegate方法从来不被称为(iOS 8 CLLo

2019-10-22 03:27发布

//查看没有加载方法 - 的LocationManager分配,并已列入.h文件中的CLLocationManagerDelegate

 -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]); } 

Answer 1:

在plist中你必须添加2项

  1. NSLocationWhenInUseUsageDescription
  2. NSLocationAlwaysUsageDescription

使双方的字符串为“位置需要找出你在哪里”或任何

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];

希望这可以帮助



文章来源: iOS 8 CLLocationManagerDelegate methods are never called