永远不会调用iOS 8 CLLocationManagerDelegate方法

时间:2015-03-03 16:40:42

标签: ios iphone cllocationmanager

  

// View已经分配了Load Method- 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]);
}

1 个答案:

答案 0 :(得分:3)

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

  1. NSLocationWhenInUseUsageDescription
  2. NSLocationAlwaysUsageDescription
  3. 将两者的字符串设为"需要位置以找出您的位置"或任何东西

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

    希望这有帮助