I'm writing a Cordova plugin for background tracking in iOS, my understanding is the following:
- I use
startUpdatingLocationto start the tracking - this will send locations whether my app is in the foreground or in the background
- if I receive a location in the background and take too much time to process it, iOS will kill the app
- this is why I also use
startMonitoringSignificantLocationChanges, so in case my app is killed iOS will reopen it with a new location indidFinishLaunchingWithOptions
is that correct?
I also have two other questions:
Monitoring significant location changes
I call startMonitoringSignificantLocationChanges to have my app relaunched if it is killed. I have read that in this case, the latest location is given in the options passed to the method, but that we have to call again both startUpdatingLocation and startMonitoringSignificantLocationChanges to keep the geolocation coming, is this correct ?
Also, if we have to call startUpdatingLocation, and (I assume) this generates a new call to the location handler with the latest location, is there a point in using the location given as parameter directly in the didFinishLaunchingWithOptions method rather than in the location handler?
It seems this would result in two parts of the code with the same processing task so this is redundant (I assume the location processing is also done in the location handler since this was the purpose of the app before it got killed -- the only case I see that might need processing in didFinishLaunchingWithOptions without restarting startUpdatingLocation is geofencing apps that only need to be awaken near a particular location without necessarily tracking the user, is this why the option is given?)
Now the question: is there a way when writing a Cordova plugin to add directly a handler to the didFinishLaunchingWithOptions method in order to call back startUpdatingLocation and startMonitoringSignificantChanges again? or is the only way to listen to the corresponding notification from the plugin code?
Javascript events when processing geolocations
The plugin calls a javascript event when it receive a location in the foreground or background. However, this javascript code might run some tasks like an animation with a timer, etc. I'd like to understand better the Cordova execution to see whether this would result in a delay that causes the app to be killed if for instance receiving a geolocation starts a javascript timer that runs an animation for too long, does this keep the application running and triggers the iOS watchdog, or is it run in a BackgroundTask thread?
And for instance if I run an AngularJS app that reacts to a new location, what happens since AngularJS has it's own run loop, will the application always be killed because AngularJS is constantly watching the variables for change etc & I have to tell AngularJS to stop its run loop when the app is in the background?
In particular, what happens if I want to asynchronously send an HTTP request to a server? Will Cordova run the js in the background or do I have to tell Cordova to wait until a certain event happens, eg the js code does the request and tells Cordova it has finished so Cordova can finish the background task?