2013-11-02 41 views
4

当Safari打开URL时,我可以轻松链接到Facebook上的特定帖子,但是我还没有找到在Facebook应用中打开该帖子的方法。在用户点击“更多帖子”之前,Facebook应用程序只显示最近三个帖子。因此,找到他们感兴趣的帖子有点困难。这是我现在的代码,它允许用户链接到Safari中的确切文章,但是如果安装了Facebook应用程序,则不会。iOS:如何从我的应用程序中在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://后/ 123456789_123456789

回答

1

如果这仍然是事情。

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

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

澄清: ID 123456_789789将成为一个数组= [123456,789789],然后你的URL看起来像这样的fb:/​​/资料/ 789789

+0

如提前实际上是试图解决它,我会记住这。三年来是漫长的等待时间:-) – Tjalsma

相关问题