简体   繁体   中英

open Facebook page from the app

I was trying to open the Facebook app with particular Facebook page from my app with the following code:

NSURL *url = [NSURL URLWithString:@"http://www.facebook.com/pagename"];
 [[UIApplication sharedApplication] openURL:url];

When I click on the button it opens the Facebook app but the required page doesn't load or show.

Is there any other way to open the Facebook app with particular Facebook page? Please correct me If I am doing something wrong.

Thanks in advance.

To open the facebook app directly you should do the following:

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString: @"fb://profile/PAGE_ID"]])
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"fb://profile/PAGE_ID"]];
}
else
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://facebook.com/PAGE_NAME"]];
}

This is a solution including a fallback for web.

To determine your PAGE_ID you could use a service like this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM