criticalmaps-ios icon indicating copy to clipboard operation
criticalmaps-ios copied to clipboard

Dynamic poll rate

Open lennet opened this issue 4 years ago • 2 comments

We are currently updating the Apps content every 12 seconds or after the user send a message as it's using the same API. This may result in an outdated map especially if a request failed because we are currently waiting another 12 seconds for the next try at which point the app might already be in the background.

It would be nice to be smarter about updating the poll the data every 6 seconds if the app is in foreground and every 12 seconds in background (maybe as well in lower power/ data mode ?). Additionally we should retry sooner, if possible as soon as possible (maybe check for internet connection on iOS 12+ devices https://developer.apple.com/documentation/network/nwpathmonitor)

lennet avatar Oct 06 '19 16:10 lennet

Hi, I would like to make this task, may I?

I have looked at RequestManager, so I think that we can poll the data every 6 seconds and for background update run application(_:performFetchWithCompletionHandler:) and BGAppRefreshTask (depends on iOS version). beginBackgroundTask(expirationHandler:) might also work, need some research here.

By the way method updateData() might be wrapped to asynchronous operation. It seems that it would be easier to control update, when we have queue.

What do you think, @lennet ?

i5glu avatar Oct 08 '19 13:10 i5glu

HI @iglushchuk , Thanks for contributing! Sure you can takeover the task.

We are using GPS updates for background scheduling so we don't need BGAppRefreshTasks as far as I know.

I though about changing the Timer fire rate but an Operation Queue also sounds like a good solution but requires more refactoring. When implementing the operation, keep in mind that we only want to send the most current location to the backend so if a request failed we shouldn't retry with the old location data

lennet avatar Oct 08 '19 16:10 lennet