Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send user to Facebook page on button click

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.

like image 796
Jeff Avatar asked Oct 07 '22 11:10

Jeff


2 Answers

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.

like image 98
esqew Avatar answered Oct 19 '22 09:10

esqew


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...

like image 25
lionserdar Avatar answered Oct 19 '22 11:10

lionserdar