I am engaged on an iOS utility utilizing Swift, and I have to commonly replace the consumer’s location each 5 minutes within the background. I am at present utilizing Core Location for dealing with location companies.
This is a simplified model of what I’ve thus far:
import CoreLocation
class LocationManager: NSObject, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
override init() {
tremendous.init()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
// Different setup for background location updates?
}
func locationManager(_ supervisor: CLLocationManager, didUpdateLocations places: [CLLocation]) {
// Deal with up to date location
}
// Different location supervisor delegate strategies...
// My query is right here: How can I guarantee location updates each 5 minutes within the background?
}
I’ve efficiently arrange location updates utilizing the above code, however I am uncertain about the perfect method to set off updates each 5 minutes, particularly when the app is within the background.
Listed below are a couple of particular questions I’ve:
What’s the perfect follow for scheduling location updates within the background each 5 minutes?
Do I have to make use of background duties or a special method?
Are there any particular concerns or configurations I have to set to optimize energy utilization?
Any steering or code examples can be tremendously appreciated! Thanks.
I appeared into utilizing the scheduledTimer technique to set off location updates each 5 minutes however realized that this does not work nicely when the app is within the background.