xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Android Deep Link & iOS Universal Link & URL Scheme All In One

Android Deep Link & iOS Universal Link & URL Scheme All In One

URL Scheme

https://developer.android.com/training/app-links/deep-linking

https://developer.apple.com/ios/universal-links/

https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html

https://developer.apple.com/documentation/uikit/inter-process_communication/allowing_apps_and_websites_to_link_to_your_content/enabling_universal_links


Mobile Safari 调用本地APP,否则进入App Store下载

URLScheme

https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/iPhoneURLScheme_Reference.pdf

https://www.zhihu.com/question/36041089

https://www.jianshu.com/p/0ead88409212

具体查找应用的URL Schemes,需要找开发商索要,当然也不是所有软件的作者都有公布,

<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="xgqfrms">
    <meta name="generator" content="VS code">
    <!-- <link rel="icon" type="image/x-icon" href="./favicon.ico" />
    <link rel="icon" type="image/png" href="./favicon.png" /> -->
    <title>URLScheme & Auto Open iOS App</title>
</head>
<body>
    <section>
        <h1>URLScheme & Auto Open iOS App</h1>
        <a href="#" data-link="app">open App</a>
    </section>
    <!-- js -->
    <script>
        let log = console.log;
        window.onhashchange = locationHashChanged;
        function locationHashChanged(e) {
            log(`location.hash`, location.hash);
            log(`e.oldURL, e.newURL`, e.oldURL, e.newURL);
            // if (location.hash === "#pageX" ) {
            //     pageX();
            // }
        }
        const autoOpenApp = () => {
            try {
                log(`try open installed app!`);
                window.location = "mqq:open";
            } catch (err) {
                log(`open app uninstalled!`, err);
                // window.location = "mqq:open";
            }
            // window.location.addEventListener(`reload`, (e) => {
            //     log(`window.location reload`, e);
            // });
            setTimeout(() => {
                let ua = navigator.userAgent.toLowerCase();
                let env = ua.includes(`mobile`) ? true : false;
                if (env) {
                    log(`app evn`, env);
                    window.location="itms-apps://itunes.apple.com/cn/app/qq-2011/id444934666?mt=8";
                } else {
                    window.location="http://itunes.apple.com/cn/app/qq-2011/id444934666?mt=8";
                    log(`browser evn`, env);
                }
            }, 1000);
        };
        document.addEventListener(`DOMContentLoaded`, () => {
            let alink = document.querySelector(`[data-link="app"]`);
            if(alink) {
                alink.addEventListener(`click`, (e) => {
                    e.preventDefault;
                    autoOpenApp();
                });
            }
        })
    </script>
</body>
</html>


hash change event

how to listen to window location change event

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onhashchange


function locationHashChanged( e ) {
    console.log( location.hash );
    console.log( e.oldURL, e.newURL );
    if ( location.hash === "#pageX" ) {
        pageX();
    }
}

window.onhashchange = locationHashChanged;

https://stackoverflow.com/questions/3522090/event-when-window-location-href-changes

https://stackoverflow.com/questions/26789364/onchange-event-on-window-location-href/26789474

MutationObserver


ar oldHref = document.location.href;

window.onload = function() {

    var
         bodyList = document.querySelector("body")

        ,observer = new MutationObserver(function(mutations) {

            mutations.forEach(function(mutation) {

                if (oldHref != document.location.href) {

                    oldHref = document.location.href;

                    /* Changed ! your code here */

                }

            });

        });

    var config = {
        childList: true,
        subtree: true
    };

    observer.observe(bodyList, config);

};


https://www.appsflyer.com/resources/everything-marketer-needs-to-know-deep-linking/universal-links/

https://wundermanthompsonmobile.com/2016/05/universallinks/

https://badootech.badoo.com/universal-links-for-android-and-ios-1ddb1e70cab0

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2019-08-20 23:21  xgqfrms  阅读(446)  评论(3编辑  收藏  举报