What is best practice to handle app updates from the app store - the ionic way?


#1

Can some one share a good way to handle application update from the app store and possibly how to redirect the user to the app store?

I am thinking to do a simple API call to the my server to check for current app version but I don’t know how to make a link to my app in the app store ( iOS - android ). do you guys have a good suggestion to handle this?


#2

I think that you can link to the web version of the app in each app store and iOS/Android will open them in the appropriate App Store/Google Play


#3

@danmilner something like so:

<a href="example.com">new version is available</a>

#4

You’ll need to use JavaScript to open it in the system browser instead of your app view. Something like:

window.open(‘http://yoururl.com’, ‘_system’);


#5

After looking into this a little more, I think a good way to go about this is creating a directive that will check the current app version via an API call. I did something like this for now

  $http.get('https://example.com/api/version').success(function (version) {
            var updateApp = document.getElementById('updateApp');
            if(version != '1.0.0'){
                $scope.appUpdate = true; // displays an update link
                ionic.Platform.isIOS()?
                updateApp.setAttribute('href', 'javascript:window.open("itms-apps://appstore.com/exampleApp", "_system")')
                :
                updateApp.setAttribute('href', 'javascript:window.open("https://play.google.com/store/apps/details?id=com.example", "_system")')
            }else{
                $scope.appUpdate = false;
            }
        })

using itms-apps://… avoids redirects. More related readings for iOS could be found here:

https://developer.apple.com/library/ios/qa/qa1633/_index.html

Thanks to @dmilner for the tip to use JS.


#6

I get the newest App Version from the server and pass it to this function that compares and if outdated, it opens Google Play Store or Apple App Store directly to my app’s page. You need to replace the links with your app page.

Also, the app version comparison is done using NPM plugin compare-versions.

function shouldUpdate(newestAppVersion) {
    // if THIS_VERSION >= newestAppVersion, does nothing
    if (newestAppVersion === undefined
        || $window.compareVersions(newestAppVersion, THIS_VERSION) <= 0) {
        return false;
    }

    if (ionic.Platform.isAndroid()) {
        $window.open("https://play.google.com/store/apps/details?id=com.example.app&hl=en","_system");

    } else {
        // iOS
        $window.open("itms-apps://itunes.apple.com/br/app/example-app/id1234567890?mt=8","_system");
    }
}