KirinJS/Kirin

JS Engine Seems to Stop on iOS device lock / screen turn off

gauntface opened this issue · 1 comments

While running a project using Kirin on the iPhone 4, if you hit the power button the screen will turn off, Javascript logic will appear to stop running and on unlocking the screen and returning back to the app the javascript will appear to kick back into gear and continue from where it was.

This has adverse affects if you're doing a networking call.

i.e. if in the middle of a network request, locking the screen prevents it from completing and returning to the app will call an error callback.

The biggest issue is there is no callback from the native code into javascript to then handle this situation. I.e. if you wanted to have an onPause method which dealt with this issue by removing any callbacks or setting a flag, you can't because the javascript is stall (i.e. none of the js methods get called)

Any non-main thread task (i.e. a call out from Javascript to native) is now set to be a background task. The background task is finished 1 second after the end of the task. This gives the Javascript time to execute an kick off any other background tasks. This is to prevent data loss of things that can be downloaded only once.