[TIMOB-26125] iOS: Sending background location updates to server
GitHub Issue | n/a |
---|---|
Type | Story |
Priority | None |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-12-11T22:30:56.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | iOS |
Labels | n/a |
Reporter | Mostafizur Rahman |
Assignee | Mostafizur Rahman |
Created | 2018-06-12T19:41:31.000+0000 |
Updated | 2018-12-11T22:30:56.000+0000 |
Description
Hello,
This user wants to send the user location updates to the server every 1 minute in the background in iOS.
The app requires to keep track of the driver’s position continuously similar to Uber and send it to the server every minute.
*Approach 1:*
They added location in UIBackgroundModes and tried using
Ti.App.iOS.registerBackgroundService({
url : ‘locationService.js’
});
and have a 1-minute interval in the locationService.js
It runs fine for 3 minutes(3 times) and then it stops.
*Approach 2:*
They tried using background fetch and added fetch in UIBackgroundModes along with location and used
Ti.App.iOS.setMinimumBackgroundFetchInterval(Ti.App.iOS.BACKGROUNDFETCHINTERVAL_MIN);
In the backgroundfetch they tried using
Ti.App.iOS.addEventListener(‘backgroundfetch’, function(e) {
handleLocationUpdate();
setTimeout(function() {
// Put the application back to sleep
Ti.App.iOS.endBackgroundHandler(e.handlerId);
}, 20000);
});
They kept a timeout before calling endBackgroundHandler
as getting the location and making the service call with the updates might take some time.
They tried without the timeout as well and still no luck.
The first problem is they cant set my desired interval of 1 min and depend on OS to execute the fetch.
Second, it gets the location and attempts to make the service call. But, the service call never goes through and they never see success/error message. But, when I bring the app to foreground immediately they see a timeout error.
Third, it executes only 3 times as before and stops again.
*Approach 3:*
Add an event listener for location update
Ti.Geolocation.addEventListener(‘location’, updateLocation);
Ti.Geolocation.distanceFilter = 10;
this approach again has a few problems
In spite of the distance filter, I keep getting the location update every sec or two.
They cant set the minUpdate time similar to Android to get once every minute.
Also if I try to use trackSignificantLocationChange
I won't get accurate values and also will get updates only after a long significant change.
They haven’t tried this approach completely as it doesn't even meet the basic requirements. So, they don't know whether they will get location updates in the background more than thrice or will the app be able to make the service call after getting the location update.
They would like forward all the 3 approaches to our R&D team which they followed and let them know if they can send user location updates to the server every 1 minute in the background in iOS.
Thanks
No comments