Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link Cordova app to App Store?

How can I create a link button in my cordova app, which is redirecting to my app on iOS/Android/Amazon App Store depending on the device?

I have tried the following code, it gets in the iOS if clause, but it doesn't redirect me, neither gives an error:

if(window.cordova && window.device) {
    if (device.platform.toUpperCase() === 'IOS') {
        window.open("https://itunes.apple.com/gb/[OBFUSCATED]");
    } else if (device.platform.toUpperCase() === 'ANDROID') {
        window.open("https://play.google.com/store/apps/details?id=[OBFUSCATED]");
    } else {
        window.open("https://www.amazon.co.uk/[OBFUSCATED]");
    }
}
like image 798
user358448 Avatar asked Jul 28 '16 08:07

user358448


2 Answers

I figured it out:

IOS: itms-apps://itunes.apple.com/app/[appId]
Android: market://details?id=[appPackageId]
Amazon: amzn://apps/android?p=[appPackageId]
like image 173
user358448 Avatar answered Sep 30 '22 21:09

user358448


you can use Inappbrowser plugin.

Install inappbrowser plugin with following command:

cordova plugin add cordova-plugin-inappbrowser

and use following in your code:

  var isAndroid = navigator.userAgent.match(/android/i) ? true : false;
    var isIOS = navigator.userAgent.match(/(ipod|ipad|iphone)/i) ? true : false;

if(isIOS){
        window.open("https://itunes.apple.com/gb/app/[OBFUSCATED]","_system");
    } else if (isAndroid) {
        window.open("https://play.google.com/store/apps/details?id=[OBFUSCATED]", "_system");
    } else {
        window.open("https://www.amazon.co.uk/[OBFUSCATED]", "_system");
    }

Hope it will help you.

Ping comment if you stuck anywhere.

like image 23
Naitik Avatar answered Sep 30 '22 21:09

Naitik