Make sure your users have the latest app version installed

Ivan Kocijan
  —  4 min read

In today’s mobile ecosystem it's easy to publish an updated version of your application. Making sure users download it is more difficult. Google and Apple provide notifications via their app stores, but more often than not, users tend to ignore them.

Annoying little update always wants to grab some attention

You can argue that it’s the users' loss if they're not interested in new features, but what if the new version fixes an important security issue? You need to make sure every user downloads the update. This can be accomplished within the application by disabling usage if it is not updated.

But how will the application know when a new update is available? Easily, with some help from our new open-source library.

Meet the prince

An Android and iOS open-source library dubbed Prince of Versions standardizes notifications about application updates. The library does all the hard work: connecting to the server, parsing the configuration file, and comparing the new version with the current one. It doesn't contain any UI, so developers can choose what to show when an update is available.

To use the library, you need to host a JSON configuration file on a server. The minimum and the current version of the application are defined in that file. When you publish a new update on Google Play, change one or both versions, and the next time the user opens your application, the library will serve a notification informing him about the new update. It is up to you to decide how the update will be shown. You can show a dialog with a button which takes the user to the app store, open a new screen, or perform some other action.

The library has three basic features:

  1. It loads a configuration file from the network and notifies the user if a new update is available
  2. Based on the minimum version in the file, it will show whether an update is mandatory
  3. It will notify the user about the update based on the notification type parameter you set up.

This library is built by developers for developers, so the implementation is straightforward.

How to use it

Little prince of versions

1. Put a JSON configuration file on a server

The version in your application and in the JSON file has to follow Semantic Versioning. If you are using a built-in JSON parser your configuration file has to look like this:

{
    "ios": {
        "minimum_version": "1.2.3",
        "latest_version": {
            "version": "2.4.5",
            "notification_type": "ALWAYS"
        }
    },
    "android": {
        "minimum_version": "1.2.3",
        "latest_version": {
            "version": "2.4.5",
            "notification_type": "ONCE"
        }
    },
    "meta": {
        "key1": "value1",
        "key2": "value2"
    }
}

2. Add the library to your project

Android

compile 'co.infinum:prince-of-versions:latest_version'

iOS

platform :ios, '8.0'
use_frameworks!

pod 'PrinceOfVersions'

run pod install

pod install

3. Check for updates

Android

PrinceOfVersions updater = new PrinceOfVersions(context); 
LoaderFactory loaderFactory = new NetworkLoaderFactory(URL);
UpdaterResult result = updater.checkForUpdates(loaderFactory, new UpdaterCallback() {
        @Override
        public void onNewUpdate(String version, boolean isMandatory, Map<String, String> metadata) {
        }

        @Override
        public void onNoUpdate(Map<String, String> metadata) {
        }

        @Override
        public void onError(@ErrorCode int error) {
        }
    });
let url = URL(string: URL)
PrinceOfVersions().checkForUpdates(from: url,
    newVersion: {
        (latestVersion, isMinimumVersionSatisfied, metadata) in
    },
    noNewVersion: {
        (isMinimumVersionSatisfied, metadata) in
    },
    error: {
        (error) in

    })

There is more

We have been using the library in production for a while and it made implementing application updates a breeze.

We all know that testing is a vital part of your development process. With the library, you can load a configuration file from the application resources. By doing this, you can test your UI implementation without making an API call.

Everybody hates constraints, so if you don’t like our JSON configuration file, you can define your own and implement a custom parser.

At the moment, these features are only available in the Android library, but they are on the roadmap for iOS and will be available soon.

If you want to contribute or have any questions about the library visit our Android or iOS repositories on GitHub.

48346133-B7BD-45CD-9E24-6CC0D844E9FF
Greetings from our lovely team!
1/4
Achievement unlocked
Resize Master