繁体   English   中英

iOS:如何在我的应用程序中打开Facebook App中的特定帖子?

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

当Safari打开URL时,我可以轻松链接到Facebook上的特定帖子,但我还没有找到在Facebook App中打开该帖子的方法。 在用户点击“更多帖子”之前,Facebook应用程序仅显示大约三个最新帖子。 所以找到他们感兴趣的帖子有点困难。这是我现在的代码,它允许用户链接到Safari中的确切帖子,但是如果安装了Facebook App则没有。

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

一个不起作用的URL,但应该:fb:// post / 123456789_123456789

如果这仍然是事情。

首先,您需要按字符“_”分割您的帖子ID。

然后使用path:fb:// profile / {id}其中{id}将等于从split中获得的数组的第二部分。 这适合我。

澄清:ID 123456_789789将成为数组= [123456,789789],然后您的网址将如下所示:fb:// profile / 789789

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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