Alagesan Palani
Alagesan Palani

Reputation: 2014

Allow IOS Webview to run in background with polling network calls

We are building an IOS app with a webview control. Webview loads a react application hosted on a webserver. React application(from webview) has a short internal polling api calls to hit api server every 20 seconds to get latest data.

However, currently when the app goes to background, webview and the polling network calls are suspended. When i bring the app to foreground, it logs as network error.

How do we allow the webview to keep making polling calls even when the app goes to background?

Upvotes: 1

Views: 2002

Answers (2)

Stefan Ticu
Stefan Ticu

Reputation: 2103

Polling from the background, especially at 20s is not only a bad practice, but will probably get your app rejected. What you should do:

  • remove your Interval when app WILL go to background ( use the applicationWillResignActive delegate)
  • remove your Interval when this will happen
  • in applicationWillEnterForeground prepare to relaunch your polling Interval

This workflow will work with quick background/foreground switches as your Interval is deleted and re-created asap.

Upvotes: 0

mars_dev
mars_dev

Reputation: 639

For this, you will have to allow the background processing of the data. In your Xcode under signing and capabilities, you will have to add background capability.

Upvotes: 1

Related Questions