0

I have tried different plugins to be able to get an app running in the background on IOS using Phonegap build. It seems however that the app is immediately suspended when the app goes in the background.

Is there anyone who have had success with any plugins, making it possible to run JavaScript in the background on an IOS device, using Phonegap build?

Fred
  • 11
  • 3
  • I have no idea if this is useful, but ... have you tried web workers? – theGleep Oct 17 '17 at 19:46
  • iOS only supports a limited set of background execution modes. You cannot execute arbitrary code for indefinite periods. Your first step is to confirm that the background execution you want is covered by one of the modes described in the iOS Application Programming Guide. Once you have identified the mode you are going to use you can research how to do it in phonegap. – Paulw11 Oct 17 '17 at 19:51
  • Hey. Thanks. Yes, I have understood that there are some restrictions, understandably so. There is a plugin called cordova-plugin-background-fetch. The iOS Background Fetch is basically an API which wakes up your app about every 15 minutes (during the user's prime-time hours) and provides your app exactly 30s of background running-time. This plugin will execute your provided callbackFn whenever a background-fetch event occurs. I havn't gotten it to work though. – Fred Oct 18 '17 at 05:13

1 Answers1

1

use this plugin : cordova-plugin-background

and in index use this code for refrech the app in background

document.addEventListener('deviceready', function () {

        cordova.plugins.backgroundMode.enable();

         cordova.plugins.backgroundMode.onactivate = function () {

           setInterval(function () {

               location.reload();

            }, 10000);
         }
       }, false);

you app it' well refrech in backround every 10000 second you can change the time

and don't forget go in xcode and enable backgroundMode

Younes Zaidi
  • 1,180
  • 1
  • 8
  • 25