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
From Monaca Cloud IDE menu, go to
Configure → Cordova Plugin Settings
.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.
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
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. | |
Force getServerVersion() to stop. | |
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. | |
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.
Parameter (JSON Object)
Property | Data Type | Description |
| Integer | A delay time in milliseconds before starting to connect to the server |
| Integer | (Android only) A time-out duration in milliseconds for connecting to the server |
| Integer | (Android only) A time-out duration in milliseconds for receiving all responses from the server |
| 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. |
| 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
forceStopGetServerVersion()
Force getServerVersion()
to stop.
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
getLocalVersion()
Get the current version of the app.
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
download()
Download the update files.
Parameter (JSON Object)
Name | Data Type | Description |
| String | The target app version |
| Integer | The update number |
| Integer | (Android only) Buffer size in bytes. The default value is |
| String | The URL where you download the ZIP file from. If this value is not existed, the value of Download URL ( |
| Integer | A delay time in milliseconds before starting to connect to the server |
| Integer | (Android only) A time-out duration in milliseconds for connecting to the server |
| Integer | (Android only) A time-out duration in milliseconds for receiving all responses from the server |
| 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. |
| 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
forceStopDownload()
Force download()
to stop.
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
updateAndRestart()
Deploy and mount the downloaded update files, and then restart the app.
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
status()
Get the current status of the plugin.
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
showAlertDialog()
Show a dialog with a title and a message. Only one dialog is shown at a time.
Parameter (JSON Object)
Name | Data Type | Description |
| String | Title of the dialog |
| String | Message content |
| JSON Object | A button in the dialog consists of 2 elements such as:
Example:
|
| JSON Object | A button in the dialog consists of 2 elements such as:
Example:
|
Return Value (Promise)
Success callback receives a JSON object indicating the result.
Fail callback receives a JSON object indicating the error(s).
Example
dismissAlertDialog()
Close the Alert dialog.
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
showProgressDialog()
Show a Progress dialog indicating the update progress.
Parameter (JSON Object)
Name | Data Type | Description |
| String | Title of the dialog |
| String | Message content |
| Integer | The maximum value of a counter. When downloading files, it will be a total number of files. |
| Integer | A value that indicates the progress. When downloading files, it will be a total number of files downloaded. |
| JSON Object | A cancel button in the dialog consists of 2 elements such as :
Example:
|
| 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
changeProgressDialog()
Change the Progress dialog.
Parameter (JSON Object)
Name | Data Type | Description |
| Integer | A value of the progress to be changed/updated. |
Return Value (Promise)
Success callback has no argument.
There is no fail callback.
Example
dismissProgressDialog()
Close a Progress dialog.
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
networkStatus()
Check the network status (Wifi, 3G/LTE, or disconnected).
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, returnfalse when there is no connection available.
Fail callback receives a JSON object indicating the error(s).
Example
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.
Parameter
None
Return Value
None
Example
autoUpdate()
Download the update files and update the app automatically.
Parameter (JSON Object)
Name | Data Type | Description |
| Integer | A delay time in milliseconds before starting to connect to the server |
| JSON Object | A dialog to be displayed while updating the app. It has 3 variables such as:
Example:
|
| Callback | A function to be called when the update is done successfully. |
| Callback | A function to be called when the update is failed. |
Return Value
None
Example
Notes on Android 9+
In principle, http protocol communication is prohibited on Android 9 and later. Therefore, the update file needs to be modified to be obtained by https protocol.
If http protocol communication is required for the operation test, you need to add the usesCleartextTraffic by adding the andorid namespace to the widget tag of config.xml as shown below.
CustomScheme configuration (Cordova 10 or later + this plugin 6.1.0 or later, iOS only)
In iOS, we can set the scheme and hostname for this plugin. (Same as HTML5 Resource Encryption plugin)
The default scheme and hostname of Cordova 10 are as follows.
Please remove this default setting. If you specify this, you will get a build error.
You can then set the scheme and hostname in config.xml as follows.
In this example, the scheme is "monacax-app" and the hostname is "monacax.io". The characters that can be used in the scheme are as shown in RFC 2396 Appendix A
Also, if you omit monaca:scheme
and moanca:hostname
, they become monaca-plugin
and monaca.plugin
respectively.
Release Note
Version | Changes |
---|---|
7.1.1 | Support cordova-ios 7.1.0 |
6.2.3 | Automatic lowercase recognition of uppercase schemes and host names |
6.2.2 | Fixed a bug when retrieving json files from external sites |
6.2.1 | Progress bar style modification |
6.2.0 | cSupport cordova-android 10 series or later (cordova-android 9 series is no longer supported) |
6.1.0 | Support CustomScheme |
6.0.0 | Support Cordova10 (Cordova9 series is no longer supported) |
Privacy Manifest
The privacy manifest required by this plugin is as follows. (cordova-ios 7.1.0 or greater)
For more information on how to write a manifesto, see https://en.docs.monaca.io/release_notes/privacy-manifest-requirement-for-ios-apps#setting-up-the-privacy-manifest .
Last updated