How do I get a background location update every n minutes in my iOS application?

后端 未结 14 1153
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 02:00

I\'m looking for a way to get a background location update every n minutes in my iOS application. I\'m using iOS 4.3 and the solution should work for non-jailbroken iPhones

相关标签:
14条回答
  • 2020-11-22 02:29
    if ([self.locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
        [self.locationManager setAllowsBackgroundLocationUpdates:YES];
    }
    

    This is needed for background location tracking since iOS 9.

    0 讨论(0)
  • 2020-11-22 02:32

    In iOS 9 and watchOS 2.0 there's a new method on CLLocationManager that lets you request the current location: CLLocationManager:requestLocation(). This completes immediately and then returns the location to the CLLocationManager delegate.

    You can use an NSTimer to request a location every minute with this method now and don't have to work with startUpdatingLocation and stopUpdatingLocation methods.

    However if you want to capture locations based on a change of X meters from the last location, just set the distanceFilter property of CLLocationManger and to X call startUpdatingLocation().

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