使用Facebook深度URL打开应用程序时,应用程序和网页会同时打开 [英] When using facebook deep URL to open app, both app and webpage open together

查看:125
本文介绍了使用Facebook深度URL打开应用程序时,应用程序和网页会同时打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将其用作网页中的链接.

I am using this as my link in webpage.

<a class="btn btn-lg btn-orange"  role="button" onclick="myFunction()">like me</a>

这是我的脚本.

function myFunction() {
    $(function(){
        window.location = "fb://profile/1456471431314551";
        setTimeout(function () { window.location = "https://www.facebook.com/angelsatwork2015"; }, 25);
    })
    }

当我在移动设备中打开时,浏览器的fb页面和fb应用程序都会打开.请提供帮助,以便在应用打开时不会重定向到fb浏览器页面. 同样,当我在台式机上使用此代码时,也会打开两个不同的浏览器页面.

When I open in mobile both the browser fb page and the fb app open. Please help so that if the app opens it does not redirect to fb browser page. Also when I use this code on desktop two different browser pages open.

推荐答案

这很可能是该代码的预期行为.

This is most likely the expected behavior for that code.

单击该按钮时,您正在做的是立即打开URL fb://profile/1456471431314551.假设这是iOS,这将导致系统显示警报,询问您是否要启动该应用.但是,从iOS 9.2开始,此警报为 non-blocking (无阻塞),这意味着其他代码将继续在后台执行.这就是为什么25毫秒后,您将URL https://www.facebook.com/angelsatwork2015作为常规网页打开的原因.

What you're doing when that button is clicked is immediately opening the URL fb://profile/1456471431314551. Assuming this is iOS, this causes the system to show an alert asking if you want the app to launch. However, as of iOS 9.2, this alert is non-blocking, which means other code continues to execute in the background. This is why, 25 milliseconds later, you're opening the URL https://www.facebook.com/angelsatwork2015 as a regular webpage.

不幸的是,在iOS 9.2+的世界中,没有很好的解决方案(感谢Apple ...).我们在 Branch.io 中所做的是通用链接的组合(在安装应用程序时会启动该应用程序...大多数时间)和重定向,例如针对通用链接无法正常工作的情况进行的重定向.我们根据设备UUID设置了跟踪Cookie,以了解何时可以安全地尝试启动该应用程序,但是实际上,这通常意味着,如果我们不确定,我们就必须重定向到App Store,以避免您的行为.遇到.

Unfortunately there is no good solution to this in the iOS 9.2+ world (thanks, Apple...). What we do at Branch.io is a combination of Universal Links (which launch the app when it is installed...most of the time) and redirections like the one you're trying for edge cases where Universal Links don't work. We set tracking cookies based on device UUID to know when we are safe to attempt launching the app, but in reality, this often means we have to redirect to the App Store if we aren't sure, just to avoid the behavior you're encountering.

这篇关于使用Facebook深度URL打开应用程序时,应用程序和网页会同时打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆