handleOpenURL() never fires

Hey guys,

I’m trying to make a custom url scheme work in my Ionic app but with no success.

I used the launchMyApp plugin, and it has correctly set up the scheme in Xcode. So my app does open when the URL scheme is called. My problem is that the handleOpenURL() function never fires.

I tried a lot of things, but none are working. Here is my code:

in <head> in my index.html

<script type="text/javascript">
      function handleOpenURL(url) {
        setTimeout(function() {
          console.log("HANDLING URL");
          // var body = document.getElementsByTagName("body")[0];
          // var mainController = angular.element(body).scope();
          // mainController.reportAppLaunched(url);
        }, 3000);
      }
</script>

As you can see the only thing it has to do is log itself to the console.

If I uncomment the lines and call handleOpenURL(url) from the chrome console, everything goes down as expected.

But this function is NEVER fired.

Any ideas ? Tell me if you need any more code / config.
Thanks a bunch !

FYI, here are my installed plugins:

com.ionic.keyboard 1.0.3 "Keyboard"
com.jcjee.plugins.emailcomposer 1.4.6 "Email Composer with Attachments"
com.verso.cordova.clipboard 0.1.0 "Clipboard"
nl.x-services.plugins.launchmyapp 3.2.0 "Custom URL scheme"
nl.x-services.plugins.socialsharing 4.3.8 "SocialSharing"
org.apache.cordova.console 0.2.11 "Console"
org.apache.cordova.core.parseplugin 0.1.0 "phonegap-parse-plugin"
org.apache.cordova.device 0.2.12 "Device"
org.apache.cordova.statusbar 0.1.8 "StatusBar"
org.pbernasconi.progressIndicator 1.0.0 "ProgressIndicator"

And my config.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.mycompany.myappid" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>myapp</name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">
      Ionic Framework Team
    </author>
  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="KeyboardDisplayRequiresUserAction" value="false" />
  <preference name="AllowInlineMediaPlayback" value="yes" />
  <preference name="BackupWebStorage" value="none"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
</widget>

Hi @charleshaa,

Can you tell me if the following works for you?:

The handleOpenURL must be a global method because it is triggered before any AngularJS fires.

Let me know if that helps you.

Regards,

Hi Nicraboy, I actually managed to fix the issue. I was using the plugin com.phonegap.plugins.facebookconnect, which was overriding the cordova handleOpenURL function. I just commented out that part, which didn’t even do anything, and now it works well !

I do in some cases have a quite big latency issue (2-3s) between the moment the app is active and the exectution of my main controller’s function though…

Hi @charleshaa, I also has the exact same problem and I’m also using the Facebook Connect, would you mind explaining what you did to fix this.

I even try this solutions , but it didnt work

thanks in advance

cheers,

Sam

Hey Sam,

Im not at my computer right now, but I remember having to go into the .m file of the plugin and look for the handleOpenURL function. I just commented it out and boom! It worked after that.

It might have been elsewhere in the code though, maybe in the SDK itself, I cant recall… I’ll check that out and come back here, even though you should be able to find it yourself :wink:

Please do bump if I forget

Hi Sam,

So I checked back and actually I think it was in the CDVParsePlugin.m from org.apache.cordova.core.parseplugin.

If you’re using this, then you should comment from line 153 to line 164. Like this:

// - (BOOL)application:(UIApplication *)application
//             openURL:(NSURL *)url
//   sourceApplication:(NSString *)sourceApplication
//          annotation:(id)annotation {
//     return [FBAppCall handleOpenURL:url
//                   sourceApplication:sourceApplication
//                         withSession:[PFFacebookUtils session]];
// }
 
//- (void)applicationDidBecomeActive:(UIApplication *)application {
//    [FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
//}

Again, it was a while ago, so I’m only like 90% sure this was the fix. Be careful, you may actually need that bit of code for other parts of your app to work.

Happy fixing

Hi @charleshaa, thanks for getting back, after some work, I was able to fix the issue by using ng-cordova-oauth plugin

But since I have the plan of integrating push notifications, I’m pretty sure your tip will save me a lot of time. thanks again :smile:

@charleshaa This is a bit of a late reply, but I handle the latency by using the $ionicLoading until the app navigates to wherever it’s supposed to. My latency isn’t that bad maybe only about 1 sec, so it doesn’t seem that out of place. Not sure about your situation though.

Hi @charleshaa i m having the same issue but i am not using the facebook connect plugin … any idea ?? how to resolve it ??

Thanks in advance :slight_smile:

@charleshaa - not to be weird or anything but I want to kiss you right now! 6 years since your post about com.phonegap.plugins.facebookconnect blocking handleOpenUrl I too am experiencing the same issue - I just cut my app over from UIWebView to WKWebView before the Apple deadline. After migrating to WKWebView I found there were a few plugins I used that still referenced UIWebView and were causing my app to be rejected from Apple Store.

So after much poking around I finally found that twitter-connect-plugin was the culprit. I removed it and all worked…I then also discovered that someone else had rewritten that same twitter plugin to be compatible with WkWebView - the new plugin cordova-plugin-twitter-connect-webview - so I installed it and all worked great. Until I spent the last 3 days trying to troubleshoot why handleOpenUrl suddenly no longer worked.

After many days of the going down the wrong rabbit hole I came across this post - and specifically your mention of FB conflicting with handleOpenUrl. aaaah haaaa! I removed the plugin and sure as hell it all worked again. M**F****! (fill in the blanks). But i would never have thought it unless I had read this thread!!!

THANKS!!!