Reputation: 811
I'm trying to open a Facebook link and using the following code would conform with the URL protocol on iOS.
NSString *url = [self.dataSource getFacebookURL];
url = [url stringByReplacingOccurrencesOfString:@"http://www.facebook.com/" withString:@"fb://profile/"];
NSLog(@"LINK: %@", url);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
But when trying to load a profile or a page (i.e. of an organization) it always brings me to the screen that was left open last. Is there a way of linking directly to the page and profile? I followed the instructions as described here, but no success.
The page I want to link to is "https://www.facebook.com/junction11" if that helps...
Thanks, Max
FIX
So I found a solution which is to load the group/person/page's graph values first, parse them and then make a new url with the Facebook-ID. The code works (don't know how well) and looks like this:
// Look at graph page instead of www page
NSString *dataURL = [url stringByReplacingOccurrencesOfString:@"www" withString:@"graph"];
// Load data and parse using JSON parser
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:dataURL]];
NSError *error;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if (!error) { NSLog(@"ERROR: %@", error); return; }
// If no error occurred, make new url and replace the username by the facebook-ID
url = [url stringByReplacingOccurrencesOfString:[dictionary objectForKey:@"username"] withString:[dictionary objectForKey:@"id"]];
// And voilà, it works :]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Thank you google and time...
Upvotes: 2
Views: 2330
Reputation: 2073
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: 1