2016-08-27 52 views
0

我試圖從我的Ionic應用程序中啓動外部應用程序。例如,Instagram。我試圖用Lampaa's Startap p插件,並遵循了前面幾個例子,但沒有成功。Ionic:啓動外部應用程序

下面是控制器內的代碼,在ng-click=""上調用。我試着在評論中解釋每個步驟正在嘗試的內容。我也想添加一個app.availability來檢查應用程序是否已安裝,但無法解決如何做到這一點。謝謝!

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

這是與您同時問的: https://stackoverflow.com/questions/39176713/how-can-i-open-another-app-using-intents-in-ionic – Ladmerc

+0

謝謝,但我也想針對iOS和Android的不同目標。它也不會在那裏的答案中使用應用內瀏覽器方法啓動應用程序;我正在專門嘗試使用Lampaa的插件 – o1n3n21

+0

控制檯中是否有任何錯誤? – e666

回答

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

} 

測試iPhone設備上。我不得不在XCode中做一些事情來使它工作。即,編輯應用程序的info.plist以允許打開外部應用程序。 這是通過添加LSApplicationQueriesSchemes作爲info.plist內的另一個屬性完成的,在此添加「instagram」或​​任何應用程序作爲「項目」。此外,您需要確保App Transport Security Settings的布爾值Allow Arbitrary Loads設置爲YES

相關問題