CLLocationManager startUpdatingLocation not calling locationManager:didUpdateLocations: or locationManager:didFailWithError:

前端 未结 8 1731
囚心锁ツ
囚心锁ツ 2020-12-05 06:21

I\'m trying to use the CLLocationManager framework in my iOS project to access the user\'s location but when I call

[locationManager startUpdat         


        
相关标签:
8条回答
  • 2020-12-05 07:21

    I think you should check this link.You are not retaining the location manager object when declaring.

    please give property to you object @property(nonatomic, strong)

    Why the CLLocationManager delegate is not getting called in iPhone SDK 4.0?

    0 讨论(0)
  • 2020-12-05 07:25

    I had the following in my code base:

    -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
        if( status == kCLAuthorizationStatusAuthorizedAlways ) {
            _locationManager = [[CLLocationManager alloc] init];
            _locationManager.delegate = self;
            _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
            _locationManager.distanceFilter = 200;
        }
    }
    

    Turns out that this was getting called in an infinite loop, because initializing a locationManager triggers this method for some reason? I had not realized that. I had put it there to catch when permissions were granted. Instead, I set up a location manager and started updating the location, but then this fired and replaced it with one that wasn't updating the location, and kept looping over and over.

    Solution for me was just to add && !_locationManager to the if condition.

    0 讨论(0)
提交回复
热议问题