Question

I'm developing a Cordova/Phonegap App which includes a database that is synchronized with an external server (internet), the database server will change frequently, what advise me to keep my application updated?

I thought of two things:

  1. Make a file called version.txt and including the version number, so I only need to see the file on the server and if it contains a greater number then run the update internal database.

  2. Make a table with a version number and do the same as in item 1.

What You advise me?

Thanks!

Was it helpful?

Solution

I've done something similar to this by creating an endpoint on my server that returns a JSON object containing the current version number.

When my app loads it makes a request to the end point and compares the JSON return to a localStorage variable in the device.

Then (like you suggested above) if the JSON return is greater than the localStorage variable, the database is updated and then the localStorage variable is updated to the value of the current JSON return.

Example:

function updateDatabase () {
    $.ajax({
        url: 'http://your_web_site.tdl/databaseversion/',
        cache: false,
        type: 'GET',
        success: function(result, status, xhr) {
            var currentVersion = result.version;
            if(!window.localStorage.getItem('localVersion') || window.localStorage.getItem('localVersion') < currentVersion) {
                //UPDATE DATABASE CODE HERE
                window.localStorage.setItem('localVersion',currentVersion);
            }
            else{
                //NO NEED TO UPDATE
            }
        },
        error: function() {
            //CANNOT GET CURRENT VERSION FROM SERVER
        }

    });
}

This assumes that your server will return the JSON:

{ version: 'X' }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top