How to stop multiple times method calling of didUpdateLocations() in ios

前端 未结 10 1135
無奈伤痛
無奈伤痛 2020-11-28 06:45

This my code......

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
 {

    location_updated = [locations lastObj         


        
10条回答
  •  一生所求
    2020-11-28 07:30

    I have similar situation. You can use dispatch_once:

    static dispatch_once_t predicate;
    
    - (void)update
    {
        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined &&
            [_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
            [_locationManager requestWhenInUseAuthorization];
        }
    
        _locationManager.delegate = self;
        _locationManager.distanceFilter = kCLDistanceFilterNone;
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    
        predicate = 0;
        [_locationManager startUpdatingLocation];
    }
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
        [manager stopUpdatingLocation];
        manager = nil;
    
        dispatch_once(&predicate, ^{
            //your code here
        });
    }
    

提交回复
热议问题