Deep Link Fallback
Asked Answered
D

2

22

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?

Dobbins answered 4/4, 2014 at 21:10 Comment(0)
W
21

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.

Worldshaking answered 18/2, 2015 at 22:38 Comment(4)
exactly what i needed , do oyu have na example for both android and IOS?Inconvincible
I tried implementing this in android, based on your answer and this doc but could not get it to work. It seems android uses slightly different uri. Would you be able to provide an example for android - where it opens the app if installed or else takes you to app store ? I tried using <a href... tag instead of iframe and on clicking on the link before it navigates to app store, i was navigated to the app correctly, but i do not want the user to have to click the linkBrinn
Chrome shows pop up which does not stop code from executing. Have you found a solution for such issue?Paniculate
This method doesn't work anymore on ios Safari cannot open the page because the address is invalidBeitz
B
1

Hi Jeffrey Nicholson Carré use android bellow intent code in javaScript

if(userAgentString.indexOf('Android')>0){
 window.location="intent://DataSchemeDataHostname/UV="+UVvalue+"&forgetuserId="+userID+"#Intent;scheme=https;package=com.sisystems.Sisystems;S.browser_fallback_url=https://example.com/index.html?UV="+UVvalue+";end"; 
 }
Bamako answered 27/2, 2020 at 7:43 Comment(2)
Sure I will Update ASAP.Bamako
please refer following url tudip.com/blog-post/deep-linking-in-react-native if u need any sample project, refer my sample xamarin project its contains Android and iOS deeplinking github.com/SheikMydeenMuthu/DeeplinkingSampleBamako

© 2022 - 2024 — McMap. All rights reserved.