Ionic: Launching external app

南楼画角 提交于 2019-12-12 02:32:33

问题


I'm trying to launch an external app from within my Ionic app. For example, Instagram. I'm attempting this with Lampaa's Startapp plug in, and have followed a few previous examples with no success.

Here's the code inside the controller, called on an ng-click="". I've tried to explain in comments what each step is attempting. I'd also like to add an app.availability to check if the app is installed, but couldn't work out how to do this either. Thanks!

$scope.onInstagramClick = function () {

// Check if
if (ionic.Platform.isAndroid()) {
// Using plugin com.lampa.startapp to launch the app for android
navigator.startApp.set({ 
    "package": "com.instagram.android",
}).start();

} else {
    if (ionic.Platform.isIOS() || ionic.Platform.isIPad()) {
               console.log('ios');
               navigator.startApp.set({ 
    "package": "instagram://",
}).start();
    } else {

         console.log('thisfailed.');
      };
    }
}

回答1:


  $scope.onInstagramClick = function () {


if (ionic.Platform.isAndroid()) {
var sApp = startApp.set("com.instagram.android");
sApp.start(function() { /* success */
    console.log("OK");
}, function(error) { /* fail */
    alert("no Instagram found");
});

} else {
    if (ionic.Platform.isIOS() || ionic.Platform.isIPad()) {
var sApp = startApp.set("instagram://");
sApp.start(function() { /* success */
    console.log("OK");
}, function(error) { /* fail */
    alert("no Instagram");
});

}

Tested on iPhone device. I had to do a few things in XCode to make it work. Namely, editing the info.plist of the application to allow external apps to open. This is done by adding LSApplicationQueriesSchemes as another property inside info.plist, here you add "instagram" or whatever app as an "Item". Moreover, you'll need to make sure App Transport Security Settings has a boolean Allow Arbitrary Loads set to YES.



来源:https://stackoverflow.com/questions/39177010/ionic-launching-external-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!