user3580117
user3580117

Reputation: 75

How to make an action button which takes user to Facebook app in iOS?

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];

Upvotes: 0

Views: 225

Answers (3)

rustylepord
rustylepord

Reputation: 5801

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];

Upvotes: 1

A J
A J

Reputation: 605

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

Upvotes: 2

Himanshu Joshi
Himanshu Joshi

Reputation: 3399

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];

Upvotes: 0

Related Questions