RRvv
RRvv

Reputation: 13

How can I open a page by Facebook application In iOS?

I have a Facebook fan page and I want to open It by Facebook application In iOS! I used this code for open a page In safari application in iOS.

NSURL *myUrl = [NSURL URLWithString:@"https://www.facebook.com/pages/example123123123"];

    if(![[UIApplication sharedApplication] openURL:myUrl]){
        NSLog(@"open Faild...");
    }

It works when Facebook application does not exist. and It opens in safari and It works. But If Facebook application be in iOS It opens by Facebook application and It doesn't work!

My question is How can I open my fan page with Facebook Application?

Upvotes: 1

Views: 2527

Answers (2)

Michael
Michael

Reputation: 435

Another method I found that works without having to do two different URL's depending on if FB app is installed. Will load in Safari fine if FB app is not installed, but uses FB app if it is.

https://www.facebook.com/your-facebook-page-id (id, not name)

And you can find your ID even easier these days by just hitting Edit Page, and going to "Page Info" tab, it's at the bottom.

Note: This does not work if you use your page name, must be page ID for some reason for the FB app to load it properly.

Upvotes: 1

Jon Steinmetz
Jon Steinmetz

Reputation: 4124

Here is an example of my Like on Facebook method:

- (IBAction) likeOnFacebook: (id) sender
{
    NSURL* facebookURL = [ NSURL URLWithString: @"https://facebook.com/jabbermouth" ];
    NSURL* facebookAppURL = [ NSURL URLWithString: @"fb://profile/157893597658332" ];
    UIApplication* app = [ UIApplication sharedApplication ];
    if( [ app canOpenURL: facebookAppURL ] ) {
        [ app openURL: facebookAppURL ];
    } else {
        [ app openURL: facebookURL ];
    }
}

The facebook app understands URLs with the form fb:// and you can test for the presence of the app using the canOpenURL method. Here is some unofficial docs for the facebook url scheme.

Upvotes: 6

Related Questions