Custom-URL-scheme icon indicating copy to clipboard operation
Custom-URL-scheme copied to clipboard

handleOpenURL() not getting triggered

Open hari5004 opened this issue 7 years ago • 6 comments

Hi Eddy, I have followed the steps for manually adding the plugin .when i click the url the app is opening but the handleOpenUrl method is not getting triggered.Please help me.

hari5004 avatar Nov 28 '17 05:11 hari5004

same as hari, I put the handleOpenUrl in main.js, but I don't know how to trigger it to get the url. Is there anything wrong with the function or the position I put? I also use vue.js in my project.

Helianthus21 avatar Dec 04 '17 10:12 Helianthus21

@hari5004 I have solved this problem, and here is my script:

window.handleOpenURL = function (url) {
    setTimeout(_ => {
        window.alert(url)
    })
}

I add this to my main.js(entry), and it works, hope it can help :)

Helianthus21 avatar Dec 05 '17 05:12 Helianthus21

According to existing code in CDVHandleOpenURL.m, your function handleOpenURL will be called when deviceready event occurs (so there is no need to wrap it with your own deviceready event handler). This function should be defined inside of your root file mentioned in config.xml with <content src="index.html" /> - the first loaded file triggering CDVPageDidLoadNotification notification.

<html>
<head>
  <script src="cordova.js"></script>
  <script>
  function handleOpenURL(url) {
    //do whatever you want
    //it is safe to call any function with setTimeout
  }
  </script>
</head>
<body>
</body>
</html>

lichkessel avatar Dec 07 '17 23:12 lichkessel

Its working for me is iOS but not in android. I have tried all options. I have added handleOpenURL function in index.html, inside onDeviceReady funciton and external js file also.

I have added handleOpenURL function in the external js but its works perfectly in iOS. But app crashes sometimes, Here is my code.

<plugin name="cordova-plugin-customurlscheme">
    <param` name="URL_SCHEME" value="macapp"/>
</plugin>`

<preference name="CustomURLSchemePluginClearsAndroidIntent" value="true"/>

function handleOpenURL(url){
   alert("URL"+url)
}

Is there anything else needs to be add?

cmohanraj10 avatar Oct 30 '18 12:10 cmohanraj10

@Helianthus21 out of curiosity, how did you handle it inside the app? I'm using Vue.js as well. Did you store it as a global variable, then within the app.vue check if there's a url in that variable, and if there is; parse it and use this.$router.push?

evinkuraga avatar Apr 26 '19 21:04 evinkuraga

@evinkuraga This is also a solution. Actually I may use:

window.handleOpenURL = function (url) {
  window.location.hash = url.slice(7) // your URLscheme.length
}

And it's too early, I don't remember much. Sorry can't help you.

Helianthus21 avatar May 06 '19 09:05 Helianthus21