Ionic App Update


Ionic App Update Cordova plugin app update is used to do the self update for android. First you need to add plugin cordova-plugin-app-update. Here in this tutorial we are going to explain how you can use Ionic App Update Plugin.


Ionic App Update | Native App Plugin Example

Run the following command to install the app update plugin –

Ionic Install App Update Plugin Command:

$ ionic plugin add --save cordova-plugin-app-update
$ npm install --save @ionic-native/app-update

Supported Platforms

  • Android– This feature is supported only in Android.

This plugin automatically updates the app, let us create a simple example to understand this.

Usage

Step 1

First you need need to create a XML file(update.xml) and host this file on server with the following content-

Ionic App Update XML:

<update>
    <version>302048</version>
    <name>APK Name</name>
    <url>https://your-remote-api.com/YourApp.apk</url>
</update>

In the above example provide the following details –

  • version – Version number to which you want update.
  • name – Apk file Name.
  • url – Apk file url path.

Step 2

Now you can use the following code to update-

Ionic App Update:

import { AppUpdate } from '@ionic-native/app-update';

constructor(private appUpdate: AppUpdate) {

   const updateUrl = 'http://your-remote-api.com/update.xml';
   this.appUpdate.checkAppUpdate(updateUrl);

}

This plugin will compare the app with the API version if API has newer version then it will automatically install it.

Instance Members

  • checkAppUpdate(updateUrl)– It checks the and performs update action. updateUrl is Update Api URL. It returns promise that resolves when something happens.

Advertisements

User Ans/Comments

How can we solve if hosting server has user authentication with this code???
 chitthushine

Add Comment

📖 Read More