检查CLLocationManager的实例是否为isUpdatingLocation

DrK*_*Key 4 objective-c cllocationmanager ios

我需要知道CLLocationManager(在这种情况下称为gps)的实例是否正在更新调用正确方法的位置

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
Run Code Online (Sandbox Code Playgroud)

在我的情况下,完整的方法是:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    //NSLog(@"didUpdateToLocation: %@", newLocation);
    currentLocation = newLocation;

    if (currentLocation != nil) {
        longitude.text = [NSString stringWithFormat:@"%.3f", currentLocation.coordinate.longitude];
        latitude.text = [NSString stringWithFormat:@"%.3f", currentLocation.coordinate.latitude];
    }

    address.text = NULL;
    [activityIndicator setHidden:NO];
    [activityIndicator startAnimating];
    NSLog(@"Resolving the Address");
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        //NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
        if (error == nil && [placemarks count] > 0) {
            placemark = [placemarks lastObject];
            [address sizeToFit];
            address.text = [NSString stringWithFormat:@"%@, %@\n%@ %@\n%@",
                            [self sanitizedDescription:placemark.thoroughfare],
                            [self sanitizedDescription:placemark.subThoroughfare],
                            [self sanitizedDescription:placemark.postalCode],
                            [self sanitizedDescription:placemark.locality],
                            [self sanitizedDescription:placemark.country]];


            if (address.text != NULL)
            {
                gpsTimer = [NSTimer scheduledTimerWithTimeInterval:10
                                                            target:gps
                                                          selector:@selector(startUpdatingLocation)
                                                          userInfo:nil
                                                           repeats:NO];
                [address sizeToFit];
                [gps stopUpdatingLocation];
            }
        } else {
            NSLog(@"%@", error.debugDescription);
        }
    } ];

}
Run Code Online (Sandbox Code Playgroud)

我能怎么做?

提前致谢 :)

Nic*_*ini 8

子类CLLocationManager并添加一个BOOL,当你的委托方法被调用时设置为yes ...

您还可以简单地告诉您的位置管理器在委托方法中停止