In-app update for Cordova based application

Dhaval Chaudhary
Fasal Engineering
Published in
4 min readNov 14, 2022

When your users keep your app up to date on their devices, they can try new features and benefit from performance improvements and bug fixes. Although some users enable background updates when their device is connected to an unmetered connection, other users might need to be reminded to install updates. In-app updates is a Google Play Core libraries feature that prompts active users to update your app. But similar functionality is not available out of the box in the iOS platform. So in our approach, we will use the Alerts functionality of apple to implement a similar feature that is available in android.

Most of the apps have started using a strategy to load dynamic resources from CDNs, which helps with quick fixes and flexible update and save time for the entire new release. But if there is a critical update in the base package or plugin it still needs an update so for such use cases this plugin becomes handy.

There are two ways android allows to perform in-app updates.

Flexible updates

Flexible updates provide background download and installation with graceful state monitoring. This UX flow is appropriate when it’s acceptable for the user to use the app while downloading the update. For example, you might want to encourage users to try a new feature that’s not critical to the core functionality of your app.

Android app flexible update
Flexible update for Ios device

Immediate updates

Immediate updates are fullscreen UX flows that require the user to update and restart the app in order to continue using it. This UX flow is best for cases where an update is critical to the core functionality of your app. After a user accepts an immediate update, Google Play handles the update installation, and the app restarts in android. In iOS, it will not allow the user to continue app usage until the user updates the application via App Store.

Android immediate update

So let’s come to the implementation part.

Here’s a link to the GitHub repo for the plugin which will help us implement in-app update functionality for android and iOS:
https://github.com/Fasal-Tech/cordova-app-update-plugin

Adding a few examples below on how to use it:

Flexible update with 5 staleness days in both android and ios



window.plugins.updatePlugin.update(()=>{
//success callback
},()=>{
//error callback
},{
IOS: {
type: "FLEXIBLE",
stallDays: 5
},
ANDROID: {
type: "FLEXIBLE",
stallDays: 5
}
});

Immediate update with 5 staleness days in both android and iOS

window.plugins.updatePlugin.update(()=>{
//success callback
},()=>{
//error callback
},{
IOS: {
type: "IMMEDIATE",
stallDays: 5
},
ANDROID: {
type: "IMMEDIATE",
stallDays: 5
}
});

Flexible update with 2 staleness days and Immediate update with 5 staleness days in both android and iOS

window.plugins.updatePlugin.update(()=>{
//success callback
},()=>{
//error callback
},{
IOS: {
type: "MIXED",
flexibleUpdateStalenessDays: 2,
immediateUpdateStalenessDays: 5
},
ANDROID: {
type: "MIXED",
flexibleUpdateStalenessDays: 2,
immediateUpdateStalenessDays: 5
}
});

Flexible update with 2 staleness days and Immediate update with 5 staleness days in both android and ios and custom messages for iOS

window.plugins.updatePlugin.update(()=>{
//success callback
},()=>{
//error callback
},{
IOS: {
type: "MIXED",
flexibleUpdateStalenessDays: 2,
immediateUpdateStalenessDays: 5,
alertTitle: "Hola new update!",
alertMessage: "Please update your app for new Features!",
alertCancelButtonTitle: "Nope",
alertUpdateButtonTitle: "Go ahead!"
},
ANDROID: {
type: "MIXED",
flexibleUpdateStalenessDays: 2,
immediateUpdateStalenessDays: 5
}
});

Here as you can see this plugin allows a customer alert message for the title description and updates and reject button. Similar functionality is not available on android.

Configuration from server

And even for the better configuration you can pass this configuration via your backend server and feed it to the plugin to work accordingly. This can give you more power in terms of handling config from your backend server.

Priority (only applicable for android)

staleness will be ignored in this case

  • If the priority of the released app is >= 3 it will trigger an Immediate update
  • If the priority of the released app is >= 1 it will trigger a Flexible update

Note: To determine priority, Google Play uses an integer value between 0 and 5, with 0 being the default, and 5 being the highest priority. To set the priority for an update, use inAppUpdatePriority the field under Edits.tracks.releases in the Google Play Developer API. Priority can only be set when rolling out a new release, and cannot be changed later.

So this is how you can implement the in-app update for Cordova-based apps (meteor, ionic, Cordova, and all other hybrid app platforms that use Cordova in the background). If you have any thoughts let me know.

--

--