Avoid an error when trying to redirect a custom protocol scheme (appname://location) if its not registered

StackOverflow https://stackoverflow.com/questions/19554398

  •  01-07-2022
  •  | 
  •  

Question

I'm using a "Bounce" web page that is linked from a text message to open my app. The "Bounce" web page essentiall does this:

<script type="text/javascript">
   window.location.href = "appname://location";
</script>

and works great if the appname:// protocol scheme is registered. But if it is not, an error message is displayed to the user:

Cannot Open Page
Safari cannot open the page because the address is invalid

Any ideas on how to attempt to do this redirect, but not show an error if its not working?

Was it helpful?

Solution

There's only a hacky javascript method to make it 'work', the invalid popup will still appear but will shortly disappear if the app is not installed, and take them to a different url

document.location = "appname://location";
setTimeout(function(){
    document.location = "http://google.com";
}, 50);

OTHER TIPS

The new way to do this is apparently Universal Links

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top