Monaca Docs
Search…
Monaca In-App Updater
This plugin updates HTML5 assets contained in the app without rebuilding and packaging the app. You need a Web server to host the update files which will be accessed from the app.
In order to use this plugin, you are required to subscribe to a valid plan. Please refer to Monaca Subscription Plans.
This plugin is not available for custom build debuggers. If you want to check the operation, you need to debug build the app.

Supported Platforms

    Cordova 7.1 or higher
    iOS 9 or later
      For WKWebView version (5.0.5 or later): iOS 11 or later
      CustomScheme supporting version(6.1.0 or later): iOS 11 or later
    Android 4.1 or later
If you are using WKWebView, you need to use version 5.0.5 or later.

Adding the Plugin in Monaca Cloud IDE

    1.
    From Monaca Cloud IDE menu, go to Configure → Cordova Plugin Settings.
    2.
    Under Available Plugins section, hover over the the InAppUpdater plugin and click Enable button.
3. Next, you need to configure necessary information for this plugin. Find your newly added plugin under the Enable Plugins section. Then, hover the plugin and click Configure button.
4. Input the CheckUpdate URL and Download URL appropriately. Then, click OK button.

Create an HTML5 asset for update

Select the following from Monaca Cloud IDE and click the Start Build button.
    Build → Build App for Android → Build for Release → Create a package for In-App Updater
    Build → Build App for iOS → Build for Release → Create a package for In-App Updater

Usage

This plugin updates the HTML5 asset for the version of the target application. When updating the HTML5 asset, set a new update number in the update file on the web server side.
For the update file on the Web server side, see CheckUpdate URL.

Plugin Configuration

To use this plugin, you need two Web APIs (URL), CheckUpdate URL and Download URL.

CheckUpdate URL

Specifies the URL of the Web API that provides update file information. Update file information is created in JSON format as follows. It can be obtained by the updateInfo parameter of a JSON object returned by the promise of getServerVersion() method.
Request Parameters
1
{
2
"ios": {
3
"2.1.0": { // app version
4
"1": { // update number
5
"date": 20170113,
6
"url": "https://hogehoge.com/app/1/ios-v2.1.0.zip" // This parameter is optional.
7
},
8
"2": { // update number
9
"date": 20170113,
10
"url": "https://hogehoge.com/app/2/ios-v2.1.0.zip" // This parameter is optional.
11
}
12
},
13
"2.2.0": { // app version
14
"1": { // update number
15
"date": 20170210,
16
"url": "https://hogehoge.com/app/1/ios-v2.2.0.zip" // This parameter is optional.
17
}
18
}
19
},
20
"android": {
21
"2.1.0": { // app version
22
"1": { // update number
23
"date": 20170113,
24
"url": "https://hogehoge.com/app/1/android-v2.1.0.zip" // This parameter is optional.
25
},
26
"2": { // update number
27
"date": 20170113,
28
"url": "https://hogehoge.com/app/2/android-v2.1.0.zip" // This parameter is optional.
29
}
30
},
31
"2.2.0": { // app version
32
"1": { // update number
33
"date": 20170210,
34
"url": "https://hogehoge.com/app/1/android-v2.2.0.zip" // This parameter is optional.
35
}
36
}
37
}
38
}
Copied!

Download URL

Specify the URL of the HTML5 asset file (zip format) for update .
You can omit this preference if you set a download URL with download.

API Reference

The easiest way to use this plugin is to only use autoUpdate() which will download the update files (as configure in Plugin Configuration) and update the app automatically.
On the other hand, if you want to customize the update process, you can use various available methods such as getServerVersion(), download(), updateAndRestart() and so on.
Here is the list of all available methods for this plugin:
Methods
Description
Get the information of files to be updated from the server.
Get the currect version of the app.
Download the update files.
Force download() to stop.
Deploy and mount the downloaded update files, and then restart the app.
status()
Get the current status of the plugin.
Show a dialog with a title and a message. Only one dialog is shown at a time.
Close the Alert dialog.
Show a Progress dialog indicating the update progress.
Change the Progress dialog.
Close a Progress dialog.
Check the network status (Wifi, 3G/LTE, or disconnected).
Terminate/Shut down the app.
Update automatically if necessary, by using methods such as getServerVersion, download, etc.

getServerVersion()

Get the information of files to be updated from the server.
1
monaca.InAppUpdater.getServerVersion([args: JSON object]): Promise
Copied!
Parameter (JSON Object)
Property
Data Type
Description
connectDelay
Integer
A delay time in milliseconds before starting to connect to the server
connectTimeout
Integer
(Android only) A time-out duration in milliseconds for connecting to the server
readTimeout
Integer
(Android only) A time-out duration in milliseconds for receiving all responses from the server
timeoutForRequest
Integer
(iOS only) A time-out duration in milliseconds for sending a request to the server. When the time-out happens, the request will be resent automatically without any errors.
timeoutForResponse
Integer
(iOS only) A time-out duration in milliseconds for receiving all responses from the server
Return Value (Promise)
    Success callback receives a JSON object as shown below:
    Property
    Data Type
    Description
    needsUpdate
    Boolean
    Indicates if the current app version needs to be updated.
    updatable
    Boolean
    Indicates if there are update files applicable to the current app version.
    latestVersion
    String
    The latest version of the app
    myVersion
    String
    The current version of the app
    latestUpdateNumber
    String
    The latest update number for the current version of the app
    myUpdateNumber
    String
    The current update number for the current version of the app
    updateInfo
    JSON Object
    The update information returned by the server after the update number. For example, if the server side response is as follows:
    {
    "ios": {
    "2.1.0": { // app version
    "1": { // update number
    "date": 20170113,
    "url": "https://hogehoge.com/app/ios-v2.1.0.zip" // This parameter is optional.
    }
    }
    }
    }
    Then, the value of updateInfo will be:
    updateInfo = {
    "date": 20170113,
    "url": "https://hogehoge.com/app/ios-v2.1.0.zip"
    }
    Fail callback receives a JSON object indicating the error(s).
Example
1
monaca.InAppUpdater.getServerVersion().then(
2
function(json) {
3
alert( JSON.stringify(json) );
4
targetVersion = json.myVersion;
5
targetUpdateNumber = json.latestUpdateNumber;
6
url = json.updateInfo.url;
7
alert( targetVersion );
8
alert( targetUpdateNumber );
9
alert( url );
10
} ,
11
function(fail) { alert( JSON.stringify(fail) ); }
12
);
Copied!

forceStopGetServerVersion()

Force getServerVersion() to stop.
1
monaca.InAppUpdater.forceStopGetServerVersion(): Promise
Copied!
Parameter
    None
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
Example
1
monaca.InAppUpdater.forceStopGetServerVersion().then(
2
function(str) { alert("stop success"); } ,
3
function(fail) { alert( JSON.stringify(fail) ); }
4
);
Copied!

getLocalVersion()

Get the current version of the app.
1
monaca.InAppUpdater.getLocalVersion(): Promise
Copied!
Parameter
    None
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
Example
1
monaca.InAppUpdater.getLocalVersion().then(
2
function(json) { alert( JSON.stringify(json) ); } ,
3
function(fail) { alert( JSON.stringify(fail) ); }
4
);
Copied!

download()

Download the update files.
1
monaca.InAppUpdater.download(args: JSON object): Promise
Copied!
Parameter (JSON Object)
Name
Data Type
Description
version
String
The target app version
updateNumber
Integer
The update number
bufferSize
Integer
(Android only) Buffer size in bytes. The default value is 8192.
url
String
The URL where you download the ZIP file from. If this value is not existed, the value of Download URL (monaca:updater_DownloadUrl in config.xml) is used instead.
connectDelay
Integer
A delay time in milliseconds before starting to connect to the server
connectTimeout
Integer
(Android only) A time-out duration in milliseconds for connecting to the server
readTimeout
Integer
(Android only) A time-out duration in milliseconds for receiving all responses from the server
timeoutForRequest
Integer
(iOS only) A time-out duration in milliseconds for sending a request to the server. When the time-out happens, the request will be resent automatically without any errors.
timeoutForResponse
Integer
(iOS only) A time-out duration in milliseconds for receiving all responses from the server
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
    Progress callback receives a JSON object indicating the progress of download as shown below:
    Name
    Data Type
    Description
    count
    Integer
    The total size of the files that have been downloaded so far
    total
    Integer
    The total size of the all expected download files
Example
1
monaca.InAppUpdater.download( { version : targetVersion, updateNumber : targetBuildNumber, url : url } ).then(
2
function(json) { alert( JSON.stringify(json) ); } ,
3
function(fail) { alert( JSON.stringify(fail) ); } ,
4
function(json) { console.log( json.count + "/" + json.total + " are done." ); }
5
);
Copied!

forceStopDownload()

Force download() to stop.
1
monaca.InAppUpdater.forceStopDownload(): Promise
Copied!
Parameter
    None
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
Example
1
monaca.InAppUpdater.forceStopDownload().then(
2
function(str) { alert("stop success"); } ,
3
function(fail) { alert( JSON.stringify(fail) ); }
4
);
Copied!

updateAndRestart()

Deploy and mount the downloaded update files, and then restart the app.
1
monaca.InAppUpdater.updateAndRestart(): Promise
Copied!
Parameter
    None
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
    Progress callback receives a JSON object indicating the progress of the deployment as shown below:
    Name
    Data Type
    Description
    count
    Integer
    The total size of the files that have been deployed so far
    total
    Integer
    The total size of the all update files to be deployed
Example
1
monaca.InAppUpdater.updateAndRestart().then(
2
function() { },
3
function(fail) { alert( JSON.stringify(fail) ); },
4
function(json) { console.log( json.count + "/" + json.total + " are done." ); }
5
);
Copied!

status()

Get the current status of the plugin.
1
monaca.InAppUpdater.status(): Promise
Copied!
Parameter
    None
Return Value (Promise)
    Success callback receives a JSON object as shown below:
    Name
    Data Type
    Description
    running
    Boolean
    Returns true if the plugin is in use.
    status
    String
    The information on what kind of task the plugin is working on right now.
    Fail callback receives a JSON object indicating the error(s).
Example
1
monaca.InAppUpdater.status().then(
2
function(json) { alert( JSON.stringify(json) ); },
3
function(fail) { alert( JSON.stringify(fail) ); }
4
);
Copied!

showAlertDialog()

Show a dialog with a title and a message. Only one dialog is shown at a time.
1
monaca.InAppUpdater.showAlertDialog(args: JSON object): Promise
Copied!
Parameter (JSON Object)
Name
Data Type
Description
title
String
Title of the dialog
message
String
Message content
button
JSON Object
A button in the dialog consists of 2 elements such as:
    label: [String] The label of the cancel button
    handler: A function to be called when the cancel button is clicked.
Example: {
label : "OK",
handler : function() { alert("OK is clicked"); }
}
cancel
JSON Object
A button in the dialog consists of 2 elements such as:
    label: [String] The label of the cancel button
    handler: A function to be called when the cancel button is clicked.
Example: {
label : "Close",
handler : function() { alert("Close is clicked"); }
}
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
Example
1
monaca.InAppUpdater.showAlertDialog({
2
title : "Title" ,
3
message : "Message" ,
4
button : { label : "OK" , handler : function() { alert( "OK is clicked"); } },
5
cancel : { label : "Cancel" , handler : function() { alert( "Cancel is clicked"); } },
6
dismiss : function() { alert("Dismissed!"); }
7
} ).then(
8
function(btnLabel) { alert( "open" ); },
9
function(fail) { alert( JSON.stringify(fail) ); }
10
);
Copied!

dismissAlertDialog()

Close the Alert dialog.
1
monaca.InAppUpdater.dismissAlertDialog(): Promise
Copied!
Parameter
    None
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
Example
1
setTimeout( function() {
2
monaca.InAppUpdater.dismissAlertDialog().then(
3
function(json) { alert( "OK auto close" ); },
4
function(fail) { alert( JSON.stringify(fail) ); }
5
);
6
} , 1000 );
Copied!

showProgressDialog()

Show a Progress dialog indicating the update progress.
1
monaca.InAppUpdater.showProgressDialog(args: JSON object): Promise
Copied!
Parameter (JSON Object)
Name
Data Type
Description
title
String
Title of the dialog
message
String
Message content
max
Integer
The maximum value of a counter. When downloading files, it will be a total number of files.
progress
Integer
A value that indicates the progress. When downloading files, it will be a total number of files downloaded.
cancel
JSON Object
A cancel button in the dialog consists of 2 elements such as :
    label: [String] The label of the cancel button
    handler: A function to be called when the cancel button is clicked.
Example:
{
label : "Close",
handler : function() { alert("Close is clicked"); }
}
dismiss
Callback
A function to be called when a dialog is closed.
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
Example
1
monaca.InAppUpdater.showProgressDialog(
2
{ title : "Title" ,
3
message : "Message" ,
4
max : 100 ,
5
progress : 50 ,
6
cancel : { label : "Cancel" , handler : function() { log("cancel handler"); } } ,
7
dismiss : function() { log("dismissed."); }
8
} ).then(
9
function(json) {
10
alert(JSON.stringify(json));
11
},
12
function(fail) {
13
alert( JSON.stringify(fail));
14
}
15
);
Copied!

changeProgressDialog()

Change the Progress dialog.
1
monaca.InAppUpdater.changeProgressDialog(args: JSON object): Promise
Copied!
Parameter (JSON Object)
Name
Data Type
Description
progress
Integer
A value of the progress to be changed/updated.
Return Value (Promise)
    Success callback has no argument.
    There is no fail callback.
Example
1
monaca.InAppUpdater.changeProgressDialog( { progress: progress } ).then(
2
function() {
3
if (progress < 100) {
4
setTimeout( function() { changeProgressDialog(progress+10); } , 500 );
5
} else {
6
monaca.InAppUpdater.dismissProgressDialog().then(
7
function(json) { log("complete"); } ,
8
function(error) { alert( JSON.stringify(error) ); }
9
);
10
}
11
}
12
)
Copied!

dismissProgressDialog()

Close a Progress dialog.
1
monaca.InAppUpdater.dismissProgressDialog(): Promise
Copied!
Parameter
    None
Return Value (Promise)
    Success callback receives a JSON object indicating the result.
    Fail callback receives a JSON object indicating the error(s).
Example
1
setTimeout( function() {
2
monaca.InAppUpdater.dismissProgressDialog().then(
3
function(json) { alert(JSON.stringify(json)); } ,
4
function(error) { alert( JSON.stringify(error) ); }
5
);
6
} , 1000 );
Copied!

networkStatus()

Check the network status (Wifi, 3G/LTE, or disconnected).
1
monaca.InAppUpdater.networkStatus(): Promise
Copied!
Parameter
    None
Return Value (Promise)
    Success callback receives a JSON object as shown below:
    Name
    Data Type
    Description
    network
    Boolean
    Return true if carrier network (i.e. Docomo, KDDI, …) is available.
    wifi
    Boolean
    Return true if Wifi is available.
    mobile
    Boolean
    Return true if a network connection (Wifi or carrier network) is available. Otherwise, return false when there is no connection available.
    Fail callback receives a JSON object indicating the error(s).
Example
1
monaca.InAppUpdater.networkStatus().then(
2
function(json) { alert( JSON.stringify(json) ); },
3
function(fail) { alert( JSON.stringify(fail) ); }
4
);
Copied!

terminateApp()

Terminate/Shut down the app.
This method is added for compatibility with the old InAppUpdater plugin ( v2.0.4 ) for Cordova 5.
For iOS, this is equivalent to shutdown/crash so we do not recommend to use. Apple might reject your app because of this.
1
monaca.InAppUpdater.terminateApp()
Copied!
Parameter
    None
Return Value
    None
Example
1
monaca.InAppUpdater.terminateApp();
Copied!

autoUpdate()

Download the update files and update the app automatically.
1
monaca.InAppUpdater.autoUpdate(options: JSON object): Promise
Copied!
Parameter (JSON Object)
Name
Data Type
Description
connectDelay
Integer
A delay time in milliseconds before starting to connect to the server
dialogMessages
JSON Object
A dialog to be displayed while updating the app. It has 3 variables such as:
    confirm3G: [String] A text to be shown when the user is using carrier network instead of Wifi connection while downloading the update.
    prepare: [JSON Object] An object with 2 string variables such as title and message which will displayed while preparing to download the updates.
    download: [JSON Object] An object with 2 string variables such as title and message which will displayed while downloading the updates.
Example:
{
confirm3G : 'These updates will be downloaded with your mobile data.',
prepare : {
title : 'Preparing to Dowload the Updates',
message : 'Now checking the server version ...'},
download : {
title : 'Dowloading the Updates',
message : 'Now downloading ...'}
}
nextTask
Callback
A function to be called when the update is done successfully.
failTask
Callback
A function to be called when the update is failed.
Return Value
    None
Example
1
monaca.InAppUpdater.autoUpdate( {
2
connectDelay : 0000,
3
connectTimeout : 30000,
4
readTimeout: 300000,
5
nextTask : function(res) {
6
if (res.requireRestart) {
7
monaca.InAppUpdater.updateAndRestart().then(
8
function() { },
9
function(fail) { alert( JSON.stringify(fail) ); }
10
);
11
} else {
12
alert("App is started!");
13
}
14
},
15
failTask : function(res) {
16
monaca.InAppUpdater.showAlertDialog(
17
{ title : "Error Code "+res.error.code ,
18
message : res.error.message ,
19
button : { label : "OK" , handler : function() { } }
20
} ).then(
21
function(json) { },
22