简体   繁体   English

Safari到Facebook应用程序的Facebook个人资料链接

[英]Facebook profile link from safari to facebook app

I am making a personal website with a link to a Facebook profile. 我正在制作一个带有Facebook个人资料链接的个人网站。 If you go to the website from iOS device, I would like the link to open in application, not safari, because a lot of people are not logged-in in safari. 如果您是从iOS设备访问网站的,那么我想在应用程序中打开该链接,而不是在safari中打开,因为很多人没有在safari中登录。

Now this can be done by using "fb://profile/" instead of the link facebook.com/. 现在,可以使用“ fb:// profile /”而不是链接facebook.com/来完成此操作。 And I have used following simple code to switch the links: 而且我使用以下简单代码来切换链接:

$(function(){
  var iOS = ( navigator.userAgent.match(/(iPhone)/g) ? true : false );
  if (iOS){
    var href= $(".fb-link").attr("href");
    var res = href.split("/");
    var username = res[res.length - 1];

    $(".fb-link").attr("href", "fb://profile/" + username);
  }
});

The only problem is when user does not have the app, then it not only won't open in an app but will fail to open completely. 唯一的问题是,当用户没有该应用程序时,它不仅不会在应用程序中打开,而且将无法完全打开。

Is there a way to test if the app is installed? 有没有一种方法可以测试该应用程序是否已安装? I know when I am programming in the iOS native app I can test if fb:// responds and then I can use the link, but the safari is way more limited. 我知道当我在iOS本机应用程序中进行编程时,我可以测试fb://是否响应,然后可以使用链接,但是Safari的使用方式受到更大的限制。 I know it probably won't be possible, just trying if anybody has some experience with this. 我知道这可能将无法实现,只是尝试是否有人对此有所了解。

Also - is there something similar for android? 另外-有类似的东西为Android吗? I don't have much experience with that. 我对此没有太多经验。

Thanks 谢谢

There's no way in Safari (from a webpage) to determine whether an app is installed or not. Safari(从网页)无法确定是否已安装应用。 The only thing you can try to do is do the fb://profile redirect in javascript, and then set a timeout on your page to see if the redirect succeeded or not. 您唯一可以尝试做的就是在javascript中执行fb:// profile重定向,然后在页面上设置超时以查看重定向是否成功。 But this is not optimal as there can be error dialogs that pop up. 但这不是最佳选择,因为可能会弹出错误对话框。

For Android, you should just go to the www url, and let the Android app handle it via its own intent filter. 对于Android,您只需转到www网址,然后让Android应用通过其自己的意图过滤器对其进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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