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

handleOpenURL

Open AidanDaniel97 opened this issue 5 years ago • 8 comments

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?

AidanDaniel97 avatar Sep 05 '19 13:09 AidanDaniel97

Does it work with [email protected]?

gasci avatar Nov 11 '19 16:11 gasci

No, it doesn't

gczudowski avatar Apr 09 '20 06:04 gczudowski

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

menzen avatar Jan 13 '21 17:01 menzen

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

gczudowski avatar Jan 13 '21 18:01 gczudowski

It works with [email protected].

gasci avatar Jan 17 '21 11:01 gasci

It works with [email protected].

Hi, I have [email protected], if the app is in the background if it works, but if the app is closed it doesn't work, even if you have [email protected], could you help me?

tmwebs avatar Jan 19 '21 08:01 tmwebs

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) }

`

menzen avatar Jan 19 '21 08:01 menzen

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#

tmwebs avatar Jan 19 '21 10:01 tmwebs