1

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?

RRvv
  • 13
  • 1
  • 3
  • 1
    Do you want to open Facebook Application for a page? If so, then instead of complete URL: try - fb://pageID or fb://pageName – Reno Jones Feb 23 '13 at 20:33

2 Answers2

6

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.

Jon Steinmetz
  • 4,104
  • 1
  • 23
  • 21
  • I don't know whay hoever It's not work! Facebook app is going to lunch but It doesn't open any page.Even when I write fb://pageIDNumber facebook app is going to lunch but anypages doesn't open. what you think about this problem? – RRvv Feb 24 '13 at 14:07
  • Does my example work correctly? If so then you need to make sure that the profile ID is correct for the app or page you are trying to open. This answer talks about how to find the facebook id http://stackoverflow.com/questions/8984468/how-to-open-facebook-page-in-facebook-app-in-iphone?rq=1. – Jon Steinmetz Feb 24 '13 at 14:38
  • Here you can find the numeric ID of any profile or page http://findmyfacebookid.com/ – Pier May 26 '14 at 05:45
1

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.

Michael
  • 435
  • 4
  • 9