EddyVerbruggen / Custom-URL-scheme

:link: Launch your Cordova/PhoneGap app by a Custom URL scheme like mycoolapp://
1.03k stars 365 forks source link

handleOpenURL() not getting triggered #262

Open hari5004 opened 6 years ago

hari5004 commented 6 years ago

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.

Helianthus21 commented 6 years ago

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 commented 6 years ago

@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 :)

lichkessel commented 6 years ago

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>
cmohanraj10 commented 5 years ago

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?

evinkuraga commented 5 years ago

@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?

Helianthus21 commented 5 years ago

@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.