Question

I have a long poll forge.request.ajax call that connects to my server to listen for new events or notifications. It works while the app is active in the foreground, but doesn't seem to work once the app is in the backgruond.

I have used the isPaused event from the forge.event module, to update the badge when new requests come in, but nothing happens. When I go back into the app, I then get the notifications sent while the app was in the background.

Is it possible to keep an longpoll ajax request open while the app is in the background?

Was it helpful?

Solution

You can't do long polling from a Trigger app while it's in the background.

When Trigger apps go into the background, JS execution is paused. Listeners for the appPaused event get called when the app goes into the background, with some constraints:

What can be executed in the callback varies by platform:

  • Android: Any javascript can be run, but timers may not be fired until the app is resumed, this prevents unnecessary battery usage by the app.
  • iOS: A short amount of time is given for execution, it is generally best to assume that callbacks and timers may not fire until the app is resumed.

This isn't something inherent to Trigger, but mobile apps in general, in particular iOS is pretty strict about how long you can run something in the background. This sort of problem is usually tackled using push notifications, which are more reliable (keep working even if your app is killed) and more battery friendly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top