2013-04-27 98 views
0

哪一行是打開Facebook和Twitter以顯示給定頁面的代碼行?在iOS的特定頁面上如何打開Facebook和Twitter

試圖與這對於Facebook

NSURL *target = [[NSURL alloc] initWithString:@"fb://profile/WindyCityCrossFit"]; [[UIApplication sharedApplication] openURL:target];

,但它只是TAKS我到我的新聞源頁。 Twitter也沒有給我任何結果。

回答

2

Facebook的:

NSURL *url = [NSURL URLWithString:@"fb://profile/130936560286785"]; [[UIApplication sharedApplication] openURL:url];

的Twitter:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=MyTwitterID"]];

+0

你應該解釋這與OP的代碼有什麼不同。 – Caleb 2013-04-27 03:26:14

+0

對不起,我的道歉。您需要使用您嘗試顯示的頁面的UID。通過查看頁面的源代碼來查找此UID。 – Stephen 2013-04-27 03:40:02

+0

我剛剛更新了我的帖子,從您的原始文章的facebook頁面的UID(130936560286785) – Stephen 2013-04-27 03:44:04

0

這應該讓你到臉書,但我不知道關於Twitter。

NSString *urlString = <your url>; 
NSString *title = <your message>; 
NSString *shareUrlString = [NSString stringWithFormat:@"http://www.facebook.com/sharer.php?u=%@&t=%@", urlString , title]; 
shareUrlString = [shareUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
      NSURL *url = [[NSURL alloc] initWithString:shareUrlString]; 
      [[UIApplication sharedApplication] openURL:url]; 
+0

什麼是標題和urlstring變量立場? – 2013-04-27 06:43:34

+0

這是如果你想用鏈接到你的URL的自動生成的帖子打開某人的Facebook。所以,它不完全回答這個問題 - 哎呀。 – Clev3r 2013-04-27 14:04:37

相關問題