Search code examples
iosiphonecordovasencha-touchbackground-process

Cordova app, backgroundmode does not work on iOS


I have a app built using Sencha Touch with Cordova. The app is basically a Google Maps map that collects the user's position once every 5th seconds.

I have installed this BackgroundMode plugin: https://github.com/katzer/cordova-plugin-background-mode

This seems to work on Android phones, but on iPhones I don't get the user's positions if they turn off the screen.

I have made sure I have the UIBackgroundModes property set in the app's plist (it has two items: "App plays audio or streams audio/video using AirPlay" and "App registers for location updates").

Any ideas what I am missing?


Solution

  • If your app is using setTimeout or setInterval to collect a user's position every 5 seconds, this will not work in the background on iOS. For iOS background location mode to work, your app needs to register for position updates using navigator.geolocation.watchPosition().

    The success function that you register with this will be called each time the iOS Location service receives a position update. This will be called whether the app is in the background or foreground, but will not be at a fixed time interval.