0

I've tried to use the code below but it keeps taking the user to show the website and I need it to take them to a application on the iPhone, ipad and ipod!

- (IBAction)fbIconGo:(id)sender {

    NSURL *fbURL = [[NSURL alloc] initWithString:@"https:facebook.com/numberHERE"];
    // check if app is installed
    if ( ! [[UIApplication sharedApplication] canOpenURL:fbURL] ) {
        // if we get here, we can't open the FB app.
        fbURL = [[NSURL alloc] initWithString:@"https:facebook.com/NUMBER HERE"];; // direct URL on FB website to open in safari
    }

    [[UIApplication sharedApplication] openURL:fbURL];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3580117
  • 75
  • 1
  • 6
  • 1
    possible duplicate of [Open Facebook app from other app](http://stackoverflow.com/questions/4725815/open-facebook-app-from-other-app) – n00bProgrammer Apr 28 '14 at 06:22

3 Answers3

2

You can do with:

NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];

Schemes

fb://profile – Open Facebook app to the user’s profile

fb://friends – Open Facebook app to the friends list

fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)

fb://feed – Open Facebook app to the News Feed

fb://events – Open Facebook app to the Events page

fb://requests – Open Facebook app to the Requests list

fb://notes – Open Facebook app to the Notes page

fb://albums – Open Facebook app to Photo Albums list

A J
  • 605
  • 4
  • 16
1

Your URLs should be changed to use the URL schemes instead , Look at these posts for the complete details,

http://wiki.akosma.com/IPhone_URL_Schemes#Facebook

Open a facebook link by native Facebook app on iOS

If you are trying to navigate to a page or a profile , the address should be as follows,

NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];
Community
  • 1
  • 1
rustylepord
  • 5,681
  • 6
  • 36
  • 49
  • I put the number in after NSURL *url = [NSURL URLWithString:@"fb://"]; "insert function here" and it only takes me to Facebook not the fan page of the app! – user3580117 Apr 28 '14 at 06:28
  • Should be something like fb://profile/number , if you want to open a page or a profile – rustylepord Apr 28 '14 at 06:30
0

You can use Apple URL schemes to communicate with other apps. Read DOCS Communicating With Other Apps

TO open facebook app use fb: URL scheme; i.e.

NSURL *url = [NSURL URLWithString:@"fb://https:facebook.com/NUMBER HERE"];
[[UIApplication sharedApplication] openURL:url];
Himanshu Joshi
  • 3,391
  • 1
  • 19
  • 32