Opening a Facebook page on iOS

One of the last features that we’ve added in our iOS version was a link to our Facebook page. While developing this feature, we had encountered a little problem.

When you are trying to open a Facebook link on a device that has Facebook app installed on it using the following command :

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/[YOUR_PAGE]“]]

you will end up opening the Facebook app when it displays the last page you accessed and not the requested page.

So how can this be solved?

The solution is that you have to change the Facebook url, instead of including [YOUR_PAGE] name in the link, you have to include your page id. In order to get [YOUR_PAGE] id, you should run the following url:

https://graph.facebook.com/[YOUR_PAGE]

By running this url you will get the following JSON answer:

{

“id”: “XXX”,

}

After extracting the “id” field from the JSON, you can now create the final URL and forward the user to it:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/[id]“]]

By the way, from what I checked, this feature is not IOS version dependent, I’ve tested it on IOS 5 and IOS 6. Also you don’t have to open it as openUrl:, you may also use UIWebView in order to complete this action.

Jane V

Chief App Developer

Price Rhythm

Posted on December 27, 2012, in Development and tagged , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 45 other followers

%d bloggers like this: