Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extremely slow updates / fps when in background mode #377

Closed
StephenCathcart opened this issue May 15, 2018 · 1 comment
Closed

Extremely slow updates / fps when in background mode #377

StephenCathcart opened this issue May 15, 2018 · 1 comment

Comments

@StephenCathcart
Copy link

Hi,

I'm writing my first mobile app using Ionic which gathers motion and gyroscope data to track movement once every 50ms. This needs to work when the user has their phone locked, hence I'm using the background mode plugin.

I'm noticing that the interval time between capturing data increases significantly when running in the background (while the phone is locked), and capturing data every 1 second rather than every 50ms.

To keep things simple, I placed a setInterval function to tick every 20ms in the constructor of a new app and to just print out Date.now(), output:

1526419240971
1526419240991
1526419241011
1526419241031   <---- Locked phone here
1526419242031
1526419243032
1526419244031
1526419245031
1526419246031

Is there anything that can be done to keep the app ticking as quickly as when it's in focus? Is this a limitation with Hybrid frameworks and would a native app be able to handle this?

Thanks

@StephenCathcart
Copy link
Author

This issue can be closed and my solution to the problem can be found here:

dorukeker/gyronorm.js#52

To summarize, browsers throttle timers (such as setInterval) to only fire once per second when out of focus (inactive tab). The hacktimer.js library can be used to prevent this.

In order for the application to continue functioning at full speed on iOS when the user has locked their phone, the following config needs to be placed inside of config.xml:

<platform name="ios">
    // other stuff
    <config-file parent="UIApplicationExitsOnSuspend" target="*-Info.plist">
        <true />
    </config-file>
</platform>

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant