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

質問

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?

役に立ちましたか?

解決

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

他のヒント

The new way to do this is apparently Universal Links

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top