What redirect URL to use when redirecting ionic for third party webflow

前端 未结 3 889
心在旅途
心在旅途 2021-01-07 07:03

I am developing a ionic mobile app in which i want to redirect to a thirdparty webflow which requests users\' consent and redirects to the callback url which i should specif

3条回答
  •  梦毁少年i
    2021-01-07 07:58

    abstract:

    This isn't exactly what you are asking for, but it works pretty well.

    The Idea is that you use $cordovaInAppBrowser to open a webview and listen for events, namely $cordovaInAppBrowser:loadstart

    and

    $cordovaInAppBrowser:loaderror

    you can then look at the error and event arguments that are passed and use those to determine if you want to call

    $cordovaInAppBrowser.close();

    which will return you to your ionic app

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

    helpful links:

    https://www.genuitec.com/products/gapdebug/

    http://ngcordova.com/docs/plugins/inAppBrowser/

提交回复
热议问题