从 iOS 应用打开 Facebook 页面的链接 [英] Open link to Facebook page from iOS app

查看:33
本文介绍了从 iOS 应用打开 Facebook 页面的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将用户重定向到我的应用程序的 Facebook 页面,所以我有以下代码:

I want to redirect user to my App's Facebook page, so I have the following code:

[[UIApplication sharedApplication] openURL:
    [NSURL URLWithString: @"https://facebook.com/myAppsPage"]];

这很好用,如果设备上没有 Facebook 应用.然后链接在 Safari 中打开.

this works great, if there is no Facebook app on device. Then the link opens in Safari.

如果设备上安装了 Facebook 应用程序,则在执行上述代码后 Facebook 应用程序打开,但它显示的是用户时间线,而不是我的应用程序页面.我试图将链接更改为 @"fb://pages/myAppsPage"@"fb://profile/myAppsPage,但这再次打开了用户时间线.

If there is Facebook app installed on device, then after executing above code Facebook app opens, but it is showing users timeline, not my app's page. I tried to change link to @"fb://pages/myAppsPage" and to @"fb://profile/myAppsPage, but this again opened users timeline.

所以,我的问题是:如果没有 Facebook 应用程序,我如何在 safari 中打开我的应用程序页面,或者如果安装了 Facebook 应用程序.

So, my question is: how can I open my apps page in safari, if there is no Facebook app, or in Facebook app, if the one is installed.

推荐答案

您必须使用给定页面的 facebook ID 而不是虚 URL.要获取页面 ID,请在以下 URL 中输入页面的虚名并复制id"的值:

You have to use the facebook ID for the given page rather than the vanity URL. To get the pages ID, enter your page's vanity name at the following URL and copy the value for "id":

https://graph.facebook.com/yourappspage

获得 id 后,您可以设置方法以使用 canOpenURL 方法检查 FB 是否已安装,并为两种状态提供适当的内容:

Once you have the id, you can set up the method to check if FB is installed using the canOpenURL method and serve the appropriate content for both states:

NSURL *facebookURL = [NSURL URLWithString:@"fb://profile/113810631976867"];
if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
    [[UIApplication sharedApplication] openURL:facebookURL];
} else {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://facebook.com"]];
}

这篇关于从 iOS 应用打开 Facebook 页面的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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