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 #304

Open AidanDaniel97 opened 4 years ago

AidanDaniel97 commented 4 years ago

I am running this function when handleOpenURL when the user has already opened the app - I am using it to get a token from a url in an email. So the user installs the app and logins in, clicks the link and this function is called:

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

this runs fine and the user is logged in. The issue comes from once I close the app and open it again and try to do that process again. Login, click the email link and then nothing happens - the handleOpenURL function isn't called at all?

gasci commented 4 years ago

Does it work with cordova-ios@5.0.0?

gczudowski commented 4 years ago

No, it doesn't

menzen commented 3 years ago

I guess i have the same issue. I open the app via custom url. If the App do a "cold start" then window.handleOpenUrl is not triggered. If the App already runs in Background, all is fine. I guess the registration of the window.handleOpenUrl is too late on a cold start, so the trigger is already gone...

gczudowski commented 3 years ago

I wasn't able to make it work. Unfortunately, my only solution was switching to a different plugin that supports deep links

gasci commented 3 years ago

It works with cordova-ios@6.1.1.

tmwebs commented 3 years ago

It works with cordova-ios@6.1.1.

Hi, I have cordova-ios@6.1.1, if the app is in the background if it works, but if the app is closed it doesn't work, even if you have cordova-ios@6.1.1, could you help me?

menzen commented 3 years ago

Hey @tmwebs , this extra cordova sticky event handler works for me to coldstart app ` if (window && 'cordova' in window) { // need this extra listener for app cold start ! window.cordova.addStickyDocumentEventHandler('handleurl'); window.handleOpenURL = url => window.cordova.fireDocumentEvent('handleurl', { url }); }

// somewhere on document / platform ready document.addEventListener('handleurl', (e: any) => isOpendFromUrl(e.url), false);

window.handleOpenURL = url => isOpendFromUrl(url)

function isOpendFromUrl(url) { console.log('isOpendFromUrl', url) }

`

tmwebs commented 3 years ago

Thanks!!!! I have managed to implement it in the following way: adding it in the index.html

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

https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/262#