/cordova-update-www

Replace content of "WWW" folder at the Cordova project

Primary LanguageC

cordova-update-www

Get current and remote version in the native code.

  1. Current version get from file index.html parse script src <script type="text/javascript" src="app.js?0.22-544-gd096e48"></script>
  2. Remote version get from server in this format (new version and note) 0.22-537|0.22-537|This version contains feature updates

If the versions do not equal show native dialog with: title: "Update Available" note: "This version contains feature updates" current: "Current version: 0.22-535" remote: "Update to: 0.22-537"

buttons: "Update Now" "Cancel"

If user tap "Update Now" we must first of all Sync evals to the server and only then update version.

And in this step maybe:

  1. builds is OK and we need Sync
  2. build is broken and we cann't call JS method

So we do test request to the JS activity.sendJavascript("UART.system.Helper.echo()");

this is method do callback to the native cordova.version(null, null, 'echo')

and if we get response during 1 second we call JS from native to do Sync

activity.sendJavascript("UART.system.Helper.syncBeforeUpdate()");

after Sync was completed JS will call native cordova.version(null, null, 'updateTo');

and download zip with new version

This is a plugin implementation of the UpdateTo Version function which can download zip from url and replace www folder at the Cordova project. Also it add url scheme to you APP and then we can start APP from another with zip to download as param - href="myapp://download/version007.zip"


Installation for Android

  1. Execute in CordovaCLI:
cordova create myApp com.name.product MyAPP
cordova pllatform add android 
cordova plugin add https://github.com/lexan1982/cordova-update-www --variable URL_SCHEME=MyAPP
  1. Go to the folder platforms\android\src\com\ideateam\app
  2. Rename MyActivity.java to MyAPP.java
  3. Open MyAPP.java and change class name from MyActivity to MyAPP
    public class MyAPP extends CordovaActivity{
            ...
     } 

Installation for iOS

Move file MainViewController.m from platforms\ios\ you-package-name \ Plugins\com.ideateam.plugin.version to the directory platforms\ios\ you-package-name \Classes


Call function cordova.version from js code with params:

cordova.version(callback, error, 'isUpdate');

callback - success function
error - error function
action

Cordova docs

MyApp