Search code examples
ioscordovaphonegap-pluginscordova-pluginsphonegap

Refresh app every time user opens it


I'm using Phonegap Cordova and have an iOS app and web app that sync information to each other, the problem I'm having though is that if the user has the iOS open on their device, but minimized, the data doesn't update realtime. So if they add something on the web app and look at the iOS app the changes wouldn't have been made on the iOS side so they'd have to close the app and relaunch. This isn't very user friendly.

Would anyone have any advice how to fix this? Perhaps refresh the app every time they open, or scroll up to refresh manually?

Any help would be great! Thank you.


Solution

  • use this plugin : cordova-plugin-background

    and in index use this code for refrech the app

    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