How to send a user to a Facebook page when a button is clicked

I am new to iOS development, so please bear with me.

I am creating a simple application. There is a facebook button, and I would like this button to send the user to my facebook page, either in the browser, or if they have a facebook application that opens.

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

+5
source share
2 answers

Starting with version 4.0 for Facebook, you can go to pages with this URI scheme:

fb://page/{fbid}

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

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

Your method might look 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
}

... ​​Interface Builder.

+2

All Articles