Deep Link Fallback

邮差的信 提交于 2020-01-11 04:27:08

问题


I will be posting links to Facebook and Twitter for deep links into my app. I have started to test with Facebook and my link works as long as the Facebook app is installed. If they don't have the Facebook app installed, they're just taken to my website.

What is best practice for handling fallback if the user doesn't have the Facebook app installed or more generally clicks on a link for my app and I always want them sent into my app?


回答1:


Great question. Rather than sharing a deep link that leads directly to your app, you should host a page on your website with fallback code in Javascript. That page can either open the app directly or fall back to the App Store (rather than your website).

Here is a concrete example of the page you would need to host on your server and link to on Facebook. It also works for emails, social media, etc. Simply substitute in your app's URI and your app's App Store link. Note that the iframe works on a greater number of browsers.

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript">
            window.onload = function() {
                // Deep link to your app goes here
                document.getElementById("l").src = "my_app://";

                setTimeout(function() {
                    // Link to the App Store should go here -- only fires if deep link fails                
                    window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
                }, 500);
            };
        </script>
        <iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
    </body>
</html>

So, if the user has your app installed, the link with the URI will succeed and the user will leave the browser before the script for redirecting to the App Store can be triggered. If the user does not have your app, the redirect succeeds (after a brief error message).

Disclosure: I'm a developer at the Branch Metrics and the above code is part of our solution to this issue.



来源:https://stackoverflow.com/questions/22873068/deep-link-fallback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!