Search code examples
angularjscordovachrome-custom-tabssfsafariviewcontroller

chrome custom tabs not redirecting back to hybrid app


Am trying to use integrate oauth in my Hybrid app and am using angularjs 1 with cordova. I tried using this plugin https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller along with https://github.com/EddyVerbruggen/Custom-URL-scheme

But its not straight forward and clear for me. Am facing two issues

  1. Unable to redirect to app after oauth is done.
  2. How to close the chrome custom tab and get the data in the app after oauth is done.

Below is what am trying.

Client Side Code:

var options=[{url:oauthPostURL,hidden:false,animated:false}];
$scope.openUrl = function(options) {
            console.log("inside openurl--");
            var deferred  = $q.defer();
            try{
                cordova.exec( 
            // success function
            function(response){
                       deferred.resolve(response);
                    },
              //failure function
                    function(response){
                        deferred.resolve(false);
                    },
              "ChromeCustomTabPlugin", "show", options);

            }catch(e){
                console.log("error in corodva plugin ::"+e);
            }
            return deferred.promise;
        }

 function handleOpenURL(url) {
  setTimeout(function() {
    //SafariViewController.hide();
    var data = decodeURIComponent(url.substr(url.indexOf('=')+1));
    console.log('Browser data received: ' + data);
  }, 0);
}

who will call this handleopenurl function ?

In the plugin there is no method for hide() to close the chrome custom tab

ServerSide :

Am using ChromeCustomTabPlugin.java from the plugin mentioned above

Please help am struggling from 2 days. It would be great if some one can provide end-to-end example


Solution

  • I solved it Myself. There are several mistakes done. I added custom-url-schema plugin manually.

    • HandleopenUrl function to be placed in page which is global, i placed the function in index.html which is my starting page.

    • LaunchMyApp.java file which is inside custom-url-plugin was missing

    • launchMyApp.js file was missing.

        <plugin name="cordova-plugin-customurlscheme" spec="^4.3.0">
            <variable name="URL_SCHEME" value="" />
            <variable name="ANDROID_SCHEME" value="" />
            <variable name="ANDROID_HOST" value="" />
            <variable name="ANDROID_PATHPREFIX" value="/" />
         </plugin>

    • This lines in config.xml was missing.