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

查看:109
本文介绍了从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应用程序,我如何打开我的应用程序页面,如果没有Facebook应用程序,或在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天全站免登陆