Custom-URL-scheme
Custom-URL-scheme copied to clipboard
handleOpenURL() not getting triggered
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.
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.
@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 :)
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>
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?
@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 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.