如何在iOS应用中添加“在Facebook上关注我们”按钮? [英] How can I add 'Follow us on facebook' button to an iOS app?
问题描述
我已经完成了我的iOS应用程序但只需要添加两个按钮:
I've about completed my iOS app but only need to add two buttons:
- 在facebook上关注我们
- 在Twitter上关注我们
我想我会在这里找到几个简单的例子,但很惊讶地发现根本没有答案(还)。
I assumed I would find a couple of simple examples here, but was surprised to find no answer to this at all (yet).
我很确定我可以在接下来的几个小时内试图解决这个问题,但我想我会伸手去拿有一点节省时间的帮助。
I'm pretty sure I could spend the next few hours trying to figure it out, but thought I'd reach out for a little time-saving help.
只需查看代码就可以查看视图控制器(XCode 4.5.1,iOS 6)上的按钮。
Just looking for the code to go behind a button on a view controller (XCode 4.5.1, iOS 6).
我假设我可能需要提供的唯一变量是公司的Facebook帐户名。
I assume the only variable I might need to supply is the company's facebook account name.
有什么建议吗? (提前致谢!)
Any suggestions? (Thanks in advance!)
推荐答案
首先,Facebook的URL方案: fb:// profile /< yourpageid>
(来源)。具有此结构的URL将打开Facebook应用程序(如果已安装)。
First, the URL schem for Facebook: fb://profile/<yourpageid>
(source). A URL with this structure will open the Facebook app, if it is installed.
点击按钮时,您可以检查Facebook是否已安装:
When your button is tapped, you can check if the Facebook is installed:
-(IBAction)fbButtonTap:(id)sender {
NSURL *fbURL = [[NSURL alloc] initWithString:@"fb://profile/<yourpageid>"];
// check if app is installed
if ( ! [[UIApplication sharedApplication] canOpenURL:fbURL] ) {
// if we get here, we can't open the FB app.
fbURL = ...; // direct URL on FB website to open in safari
}
[[UIApplication sharedApplication] openURL:fbURL];
}
对于Twitter,您可以遵循相同的基本步骤。 iOS的Twitter URL方案是 twitter:// user?id = 12345
或 twitter:// user?screen_name = yourname
(来源)。同样,如果没有安装Twitter应用程序,你可以在safari中打开twitter个人资料。
For twitter, you follow the same basic steps. The Twitter URL scheme for iOS is twitter://user?id=12345
or twitter://user?screen_name=yourname
(source). Again, if the Twitter app is not installed, you have open the twitter profile in safari.
至于采取直接行动,我认为你不能这样做,因为关于设备上安装的任何其他应用程序,没有固有的知识。我认为你能做的最好的就是将用户引导到各自的账户。
As for taking direct actions, I do not think you can do that, since there is no inherent knowledge about any other applciation installed on the device. The best I think you can do is direct users to each respective account.
这篇关于如何在iOS应用中添加“在Facebook上关注我们”按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!