抽象的:
这并不完全是您所要求的,但效果很好。
这个想法是你使用$cordova InAppBrowser打开网络视图并监听事件,即$cordovaInAppBrowser:loadstart
and
$cordovaInAppBrowser:loaderror
然后,您可以查看传递的错误和事件参数,并使用它们来确定是否要调用
$cordovaInAppBrowser.close();
这将使您返回到您的离子应用程序
code:
angular.module('myApp', ['ionic', 'ngCordova']).controller('AppCtrl', function($rootScope, $ionicPlatform, $cordovaInAppBrowser) {
$scope.openThirdPartyWhatever = function() {
$ionicPlatform.ready(function() {
var options = {
location: 'yes',
clearcache: 'no',
toolbar: 'yes'
};
$cordovaInAppBrowser.open('http://www.myAwesomeSite.com', '_blank', options)
});
};
//at some point your app tries to load 'http://localhost:8100/send-me-back-to-app'
$rootScope.$on('$cordovaInAppBrowser:loadstart', function(e, event) {
//and this function is called, so you do something like
if(event.url === 'http://localhost:8100/send-me-back-to-app'){
$cordovaInAppBrowser.close();
}
});
$rootScope.$on('$cordovaInAppBrowser:loaderror', function(e, event) {
$cordovaInAppBrowser.close();
alert('sorry, something went wrong');
});
});
有用的网址:
https://www.genuitec.com/products/gapdebug/
http://ngcordova.com/docs/plugins/inAppBrowser/