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.
- 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.
- 1.From Monaca Cloud IDE menu, go to
Configure → Cordova Plugin Settings
. - 2.Under Available Plugins section, hover over the the
InAppUpdater
plugin and clickEnable
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.

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
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.
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
{
"ios": {
"2.1.0": { // app version
"1": { // update number
"date": 20170113,
"url": "https://hogehoge.com/app/1/ios-v2.1.0.zip" // This parameter is optional.
},
"2": { // update number
"date": 20170113,
"url": "https://hogehoge.com/app/2/ios-v2.1.0.zip" // This parameter is optional.
}
},
"2.2.0": { // app version
"1": { // update number
"date": 20170210,
"url": "https://hogehoge.com/app/1/ios-v2.2.0.zip" // This parameter is optional.
}
}
},
"android": {
"2.1.0": { // app version
"1": { // update number
"date": 20170113,
"url": "https://hogehoge.com/app/1/android-v2.1.0.zip" // This parameter is optional.
},
"2": { // update number
"date": 20170113,
"url": "https://hogehoge.com/app/2/android-v2.1.0.zip" // This parameter is optional.
}
},
"2.2.0": { // app version
"1": { // update number
"date": 20170210,
"url": "https://hogehoge.com/app/1/android-v2.2.0.zip" // This parameter is optional.
}
}
}
}
Specify the URL of the HTML5 asset file (zip format) for update .
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. | |
Deploy and mount the downloaded update files, and then restart the app. | |
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. |
Get the information of files to be updated from the server.
monaca.InAppUpdater.getServerVersion([args: JSON object]): Promise
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:PropertyData TypeDescription
needsUpdate
BooleanIndicates if the current app version needs to be updated.updatable
BooleanIndicates if there are update files applicable to the current app version.latestVersion
StringThe latest version of the appmyVersion
StringThe current version of the applatestUpdateNumber
StringThe latest update number for the current version of the appmyUpdateNumber
StringThe current update number for the current version of the appupdateInfo
JSON ObjectThe 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
monaca.InAppUpdater.getServerVersion().then(
function(json) {
alert( JSON.stringify(json) );
targetVersion = json.myVersion;
targetUpdateNumber = json.latestUpdateNumber;
url = json.updateInfo.url;
alert( targetVersion );
alert( targetUpdateNumber );
alert( url );
} ,
function(fail) { alert( JSON.stringify(fail) ); }
);
Force
getServerVersion()
to stop.monaca.InAppUpdater.forceStopGetServerVersion(): Promise
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
monaca.InAppUpdater.forceStopGetServerVersion().then(
function(str) { alert("stop success"); } ,
function(fail) { alert( JSON.stringify(fail) ); }
);
Get the current version of the app.
monaca.InAppUpdater.getLocalVersion(): Promise
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
monaca.InAppUpdater.getLocalVersion().then(
function(json) { alert( JSON.stringify(json) ); } ,
function(fail) { alert( JSON.stringify(fail) ); }
);
Download the update files.
monaca.InAppUpdater.download(args: JSON object): Promise
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:NameData TypeDescription
count
IntegerThe total size of the files that have been downloaded so fartotal
IntegerThe total size of the all expected download files
Example
monaca.InAppUpdater.download( { version : targetVersion, updateNumber : targetBuildNumber, url : url } ).then(
function(json) { alert( JSON.stringify(json) ); } ,
function(fail) { alert( JSON.stringify(fail) ); } ,
function(json) { console.log( json.count + "/" + json.total + " are done." ); }
);
Force
download()
to stop.monaca.InAppUpdater.forceStopDownload(): Promise
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
monaca.InAppUpdater.forceStopDownload().then(
function(str) { alert("stop success"); } ,
function(fail) { alert( JSON.stringify(fail) ); }
);
Deploy and mount the downloaded update files, and then restart the app.
monaca.InAppUpdater.updateAndRestart(): Promise
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:NameData TypeDescription
count
IntegerThe total size of the files that have been deployed so fartotal
IntegerThe total size of the all update files to be deployed
Example
monaca.InAppUpdater.updateAndRestart().then(
function() { },
function(fail) { alert( JSON.stringify(fail) ); },
function(json) { console.log( json.count + "/" + json.total + " are done." ); }
);
Get the current status of the plugin.
monaca.InAppUpdater.status(): Promise
Parameter
- None
Return Value (Promise)
- Success callback receives a JSON object as shown below:NameData TypeDescription
running
BooleanReturnstrue
if the plugin is in use.status
StringThe information on what kind of task the plugin is working on right now. - Fail callback receives a JSON object indicating the error(s).
Example
monaca.InAppUpdater.status().then(
function(json) { alert( JSON.stringify(json) ); },
function(fail) { alert( JSON.stringify(fail) ); }
);
Show a dialog with a title and a message. Only one dialog is shown at a time.
monaca.InAppUpdater.showAlertDialog(args: JSON object): Promise
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:
Example:
{ label : "OK", handler : function() { alert("OK is clicked"); } } |
cancel | JSON Object | A button in the dialog consists of 2 elements such as:
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
monaca.InAppUpdater.showAlertDialog({
title : "Title" ,
message : "Message" ,
button : { label : "OK" , handler : function() { console.log("OK is clicked"); } },
cancel : { label : "Cancel" , handler : function() { console.log("Cancel is clicked"); } },
dismiss : function() { console.log("Dismissed!"); }
} ).then(
function(btnLabel) { console.log("open"); },
function(fail) { console.log(JSON.stringify(fail)); }
);
Close the Alert dialog.
monaca.InAppUpdater.dismissAlertDialog(): Promise
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
setTimeout( function() {
monaca.InAppUpdater.dismissAlertDialog().then(
function(json) { console.log("OK auto close"); },
function(fail) { console.log(JSON.stringify(fail)); }
);
} , 1000 );
Show a Progress dialog indicating the update progress.
monaca.InAppUpdater.showProgressDialog(args: JSON object): Promise
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 :
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
monaca.InAppUpdater.showProgressDialog(
{ title : "Title" ,
message : "Message" ,
max : 100 ,
progress : 50 ,
cancel : { label : "Cancel" , handler : function() { console.log("cancel handler"); } } ,
dismiss : function() { console.log("dismissed."); }
} ).then(
function(json) {
console.log(JSON.stringify(json));
},
function(fail) {
console.log(JSON.stringify(fail));
}
);
Change the Progress dialog.
monaca.InAppUpdater.changeProgressDialog(args: JSON object): Promise
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
monaca.InAppUpdater.changeProgressDialog( { progress: progress } ).then(
function() {
if (progress < 100) {
setTimeout( function() { changeProgressDialog(progress+10); } , 500 );
} else {
monaca.InAppUpdater.dismissProgressDialog().then(
function(json) { console.log("complete"); } ,
function(error) { console.log(JSON.stringify(error)); }
);
}
}
)
Close a Progress dialog.
monaca.InAppUpdater.dismissProgressDialog(): Promise
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
setTimeout( function() {
monaca.InAppUpdater.dismissProgressDialog().then(
function(json) { console.log(JSON.stringify(json)); } ,
function(error) { console.log(JSON.stringify(error)); }
);
} , 1000 );
Check the network status (Wifi, 3G/LTE, or disconnected).
monaca.InAppUpdater.networkStatus(): Promise
Parameter
- None
Return Value (Promise)
- Success callback receives a JSON object as shown below:NameData TypeDescription
network
BooleanReturntrue
if carrier network (i.e. Docomo, KDDI, …) is available.wifi
BooleanReturntrue
if Wifi is available.mobile
BooleanReturntrue
if a network connection (Wifi or carrier network) is available. Otherwise, returnfalse when there is no connection available.
- Fail callback receives a JSON object indicating the error(s).
Example
monaca.InAppUpdater.networkStatus().then(
function(json) { alert( JSON.stringify(json) ); },
function(fail) { alert( JSON.stringify(fail) ); }
);
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.
monaca.InAppUpdater.terminateApp()
Parameter
- None
Return Value
- None
Example
monaca.InAppUpdater.terminateApp();
Download the update files and update the app automatically.
monaca.InAppUpdater.autoUpdate(options: JSON object): Promise
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:
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
monaca.InAppUpdater.autoUpdate( {
connectDelay : 0000,
connectTimeout : 30000,
readTimeout: 300000,
nextTask : function(res) {
if (res.requireRestart) {
monaca.InAppUpdater.updateAndRestart().then(
function() { },
function(fail) { alert( JSON.stringify(fail) ); }
);
} else {
alert("App is started!");
}
},
failTask : function(res) {
monaca.InAppUpdater.showAlertDialog(
{ title : "Error Code "+res.error.code ,
message : res.error.message ,
button : { label : "OK" , handler : function()