Jump to third-party app for Cordova plug-ins

created by diwj on 20171205

Step 1: Install the Cordova plug-in

cordova plugin add https://github.com/lampaa/com.lampa.startapp.git //Non-cordova official plug-in, open third-party app s
cordova plugin add cordova-plugin-appavailability --save//Detect the existence of third-party app s

cordova plugin add cordova-plugin-inappbrowser //Apply built-in browser

Step 2:Config.xmlNeed to configure permissions

1.ios configuration
Note: As long as there are ipa files, changing the suffix name to zip can be used as zip decompression. After decompression, you can see the.plist file. If you see the file scrambled, you can download plistEditor or related tools to view it

 <allow-intent href="A://*/*" />
 //A Is Scheme Name, corresponding to CFBundleURLSchemes in the.plist file
 <allow-intent href="B://*/*" />
 //B is AppName, corresponding to CFBundleName in the.plist file

2.android Configuration

 <allow-intent href="C://*/*" />
 //C is the scheme of app

Step 3: Decide which platform your system belongs to and execute different codes

//You must install the cordova-plugin-device plugin order to use the following judgment
var scheme;  
      if(device.platform === 'iOS') {
          scheme="A"//A Ibid.
      else if(device.platform === 'Android') {
          scheme="D"//D is Package Name

Step 4: Detect if the app exists, open if it exists, and open the download link if it does not exist

1. Implementation of iosCheck method

function iosCheck(scheme){
          scheme,       // URI Scheme or Package Name
          function() {  // Success callback
            alert(scheme + ' is available :)');
            var sApp = startApp.set(scheme);
            sApp.start(function() { /* success */
            }, function(error) { /* fail */

          function() {  // Error callback
            console.log(scheme +"Not available")
            var confirmPopup = $ionicPopup.confirm({
              title: 'Friendship Tips',
              template: 'You have not installed the app,Is it installed', 
              okText: 'go AppStore',
              cancelText:'Don't install yet',
              cancelType: 'item-customer-bg-lightred'
                console.log("Installation in progress......")
                window.open('Download Link Address')
                console.log("Cancel Installation......")

2. Specific implementation of androidCheck method

function androidCheck(sheme){
          scheme,       // URI Scheme or Package Name
          function() {  // Success callback
              console.log(scheme + ' is available :)');
              var sApp = startApp.set({ /* params */
            // "component": ["com.android.GoBallistic","com.android.GoBallistic.Activity"],
              }, { /* extras */
              sApp.start(function() { /* success */
                 console.log("open  success")
              }, function(error) { /* fail */
                 console.log("open  failed")

          function() {  // Error callback
              console.log(scheme + ' is not available :(');

Finally, a whitelist is required in ios9+, otherwise it cannot be detected

    //AB means the same thing, configuring the path platforms/projectName/XXX-Info.plist

Tags: Android iOS github git

Posted on Wed, 15 Jul 2020 11:41:04 -0400 by Balmung-San