【问题标题】:iOS: How do I open a specific post in the Facebook App from within my application?iOS:如何在我的应用程序中打开 Facebook 应用程序中的特定帖子?
【发布时间】:2013-11-13 18:41:20
【问题描述】:

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

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

一个无效的网址,但应该是:fb://post/123456789_123456789

【问题讨论】:

    标签: ios facebook


    【解决方案1】:

    如果还是这样的话。

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

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

    澄清: ID 123456_789789 将变成一个数组 = [123456,789789] 然后你的 url 看起来像这样 fb://profile/789789

    【讨论】:

    • 我会在实际尝试之前将其标记为已解决。三年的等待时间很长:-)
    猜你喜欢
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 2023-04-03
    • 2015-07-27
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-12-02
    相关资源
    最近更新 更多