A significant change in location does not work at least every 15 minutes

According to apple docs, a significant change in location should update the location at least every 15 minutes. I really get updates when I move significantly, but not when the device is stationary. What is your upgrade experience? Do they appear at least every 15 minutes?

If the accuracy of the GPS level is not important for your application, and you do not need continuous tracking, you can use a significant change in the location of the provision of services. Its important that you use the location with a significant change correctly, because it wakes up the system and your application at least every 15 minutes, even if no location changes have occurred, and it works continuously until you stop it.

+4
source share
1 answer

Ok, I have a naive solution. You can use NSTimer to force the CLLocationManger instance to update its current location every 15 minutes or the time you want to update periodically.

, :

, , , viewDidLoad .

- (void)startStandardUpdates
{
    if (nil == locationManager){
        locationManager = [[CLLocationManager alloc] init];
    }

    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    // 900 seconds is equal to 15 minutes
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:900 target:self selector:@selector(updateUserLocation) userInfo:nil repeats:YES];
    [timer fire];    
}

-, updateUserLocation:

-(void)updateUserLocation{
    [self.locationManager startUpdatingLocation];
}

, , . 15 .:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    CLLocation *userLocation = [locations objectAtIndex:0];
    CLLocationCoordinate2D userLocationCoordinate = userLocation.coordinate;
    /*
    Do whatever you want to update by using the updated userLocationCoordinate.
    */
    [manager stopUpdatingLocation];
}
+2

Source: https://habr.com/ru/post/1629375/


All Articles