简体   繁体   中英

iOS: How do I open a specific post in the Facebook App from within my application?

I can easily link to a specific post on Facebook when Safari opens the URL, but I have yet to find a way to open that post in the Facebook App. The Facebook App only displays about three most recent posts before the user has to click 'More Posts'. So it's a bit of a struggle to find the post they are interested in. This is my code now, which allows users to link to the exact post in Safari, but not if the Facebook App is installed.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *postID = [[parsedPosts objectAtIndex:[indexPath indexAtPosition:1]] objectForKey:@"post_id"];
    NSArray *idParts = [postID componentsSeparatedByString:@"_"];
    UIApplication *sharedApp = [UIApplication sharedApplication];
    NSURL *faceBookURL = [NSURL URLWithString:[NSString stringWithFormat:@"fb://profile/%@", [idParts objectAtIndex:0]]];
    if([sharedApp canOpenURL:faceBookURL]){
         [sharedApp openURL:faceBookURL];
    } else {
        NSURL *safariURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://m.facebook.com/story.php?story_fbid=%@&id=%@", [idParts objectAtIndex:1], [idParts objectAtIndex:0]]];
        [sharedApp openURL:safariURL];
    }
}

A URL that dosen't work, but should: fb://post/123456789_123456789

If this is still the thing.

First, you need to split your post id by character "_".

Then use path: fb://profile/{id} where {id} will be equal to the second part of array obtained from the split. This works for me.

The clarification: ID 123456_789789 will become an array = [123456,789789] and then your url will look like this fb://profile/789789

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