Ionic:启动外部应用程序 [英] Ionic: Launching external app

查看:527
本文介绍了Ionic:启动外部应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的Ionic应用程序中启动外部应用程序。例如,Instagram。我正在尝试使用 Lampaa的Startap 插件,并按照之前的几个示例进行操作没有成功。

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.

这是控制器内部的代码,在 ng-click =上调用。我试图在评论中解释每一步的尝试。我还想添加一个app.availability来检查应用程序是否已安装,但无法解决如何执行此操作。谢谢!

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.');
      };
    }
}


推荐答案

  $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");
});

}

在iPhone设备上测试。我必须在XCode中做一些事情才能使它工作。即,编辑应用程序的 info.plist 以允许打开外部应用程序。
这是通过在 info.plist 中添加 LSApplicationQueriesSchemes 作为另一个属性来完成的,在这里添加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.

这篇关于Ionic:启动外部应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆