简体   繁体   中英

Is it possible to browser deeplink to an app? (without popup)

I'm trying to deeplink into an app from the browser, that's working fine. But the problem is, that iOS is showing a "Safari can't open the page" and then redirects to the app store (fallback solution).

Is it possible to make some JS magic, so that popup box doesn't appear?

Here is the code:

    var now = new Date().valueOf();
    setTimeout(function () {
        if (new Date().valueOf() - now > 100) return;
        window.location = "https://itunes.apple.com/us/app/twitter/id333903271?mt=8";
    }, 10);
    window.location = "twitter://timeline";

I encountered a similar scenario some time back and I figured the best way to go about is have an iframe and provide a source to it..

function mobileDeepLink() {
    var iframe = document.createElement('iframe');
    iframe.src = "twitter://timeline";

    // hide iframe visually
    iframe.width = 0;
    iframe.height = 0;
    iframe.frameBorder = 0;

    var now = new Date().valueOf();
    setTimeout(function () {
        if (new Date().valueOf() - now > 100) return;
        window.location = "https://itunes.apple.com/us/app/twitter/id333903271?mt=8";
    }, 10);

    // Append it to the body.
    document.body.appendChild(iframe);
    iframe.parentNode.removeChild(iframe);
}

mobileDeepLink();

That way you would not see the error popup when the scheme cannot be found.

Update

This approach will only work for IOS 8 and lower. From IOS 9 and later, deep linking is being supported natively using universal links.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM