简体   繁体   中英

Objective-C - Core Location - iOS 7.1

I have a code in a UIViewController that starts the location update: [locationManager startUpdatingLocation];

Is working perfectly. But I need every time you exit this screen it stops updating the location and start again when I return.

The first time it for updates. In other times it does not stop.

Code for exit from view:

[locationManager stopUpdatingLocation];
locationManager.delegate = nil;

Ihave tried also: (without success too)

[locationManager stopMonitoringSignificantLocationChanges];
[locationManager stopUpdatingHeading];
[locationManager stopUpdatingLocation];

locationManager.delegate = nil;
locationManager = nil;

It always update. But from the second time not stop update.

didUpdateLocation code:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ [self addingMarkerUser]; }

You should put your code in the viewDidAppear and i suppose in your [self addingMarkerUser] you use something like this without the stop (if not, please provide the code) :

CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
    [geocoder reverseGeocodeLocation:_currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {

 if (!(error)) {
              //do something with the data.
              //then stop the update.
            [locationManager stopUpdatingLocation];

        }
    }];

If you do like that, every time your view appear, the location will start the update then stop once the data retrieve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM