How to send user to Facebook page on button click

坚强是说给别人听的谎言 提交于 2019-12-10 14:05:27

问题


I'm new to iOS development so please bear with me..

I'm in the process of creating a simple app. There is a facebook button and I'd like that button to send the user to my facebook page, either in the browser or if they have the facebook app open that up.

I know there's probably a lot to explain, but if someone could point me in the right direction that would be great, thanks.


回答1:


As of the 4.0 update for Facebook, you can jump to pages with this URI schema:

fb://page/{fbid}

Just make sure you check to make sure that the device you're working with can respond to it:

[[UIApplication sharedApplication] canOpenURL:[NSURL urlWithString:@"fb://page/{fbid}"]];

Your method might end up looking something like this:

- (IBAction)openFBPage:(id)sender {
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL urlWithString:@"fb://page/{fbid}"]]) {
        [[UIApplication sharedApplication] openURL:[NSURL urlWithString:@"fb://page/{fbid}"]];
    } else {
        NSLog(@"Facebook isn't installed.");
        // or do the sensible thing and openURL the HTTP version of the page in safari
}

... and you'd link the above method with your button in Interface Builder.




回答2:


You need to download the FacebookSDK and follow the steps that are described over there. Check out this page https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/3.1/

Hope helps...



来源:https://stackoverflow.com/questions/12680205/how-to-send-user-to-facebook-page-on-button-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!