I need to be able to get precise location updates continuously even if the app is terminated.
Here is my scenario:
My job is that I have to get the location updates every second whenever the user is driving on delivery routes even if the app is terminated to monitor the user's car trips and give the user a report of the trips.
I know how to get if the user is driving using CMMotionActivityManager
let motionActivityManager = CMMotionActivityManager()
motionActivityManager.startActivityUpdates(to: operationqueue,withHandler: motionActivityHandler)
I'm also familiar with starting updating location from the foreground and enabling background modes for location updates.
let locationManager = CLLocationManager()
locationManager.allowsBackgroundLocationUpdates = true
locationManager.showsBackgroundLocationIndicator = true
locationManager.pausesLocationUpdatesAutomatically = false
locationManger.startUpdatingLocation()
But the idea is that I don't want to start the location updates from the foreground and minimize the app so that I don't waste a lot of energy, and if the user chooses to close the app from the App Switcher it will kill the app and the location updates and that's not what I need.
I'm using locationManager.startMonitoring(for: Region) because the system automatically relaunches the app into the background when the user exits or enters the region and then I check if he is driving and if that was true I start locationManger.startUpdatingLocation() but the problem here is that the app only runs for 10 seconds and even if I turned on the location updates which are allowed to work in the background the systems shuts down the app.
Also tried locationManager.startMonitoringSignificantLocationChanges() which is also like the region monitoring the system relaunches the app into the background but only when the user moves for about 500 meters and also the app won't work for enough time to monitor a full trip.
Also tried to work with SwiftBackgroundLocation library but it won't work correctly on real devices.
I need to be able to turn the location updates form the background and get location updates continuously and only when the user stops driving I stop location updates and stop the app.
Also is there is a way to get an exception from apple to work in the background like that if we applied for some kind of a special entitlement for the app (if the user installed the app then he wants to monitor his trips and of course he is told about the location updates running in the background).
Sorry for the long question.
Selecting any option will automatically load the page