2014-04-28 82 views
0

我試過使用下面的代碼,但它一直讓用戶顯示網站,我需要它將它們帶到iPhone,iPad和iPod上的應用程序!如何製作一個操作按鈕,讓用戶訪問iOS應用程序中的Facebook應用程序?

- (IBAction)fbIconGo:(id)sender { 

    NSURL *fbURL = [[NSURL alloc] initWithString:@"https:facebook.com/numberHERE"]; 
    // check if app is installed 
    if (! [[UIApplication sharedApplication] canOpenURL:fbURL]) { 
     // if we get here, we can't open the FB app. 
     fbURL = [[NSURL alloc] initWithString:@"https:facebook.com/NUMBER HERE"];; // direct URL on FB website to open in safari 
    } 

    [[UIApplication sharedApplication] openURL:fbURL]; 
+1

[從其他應用中打開Facebook應用](http://stackoverflow.com/questions/4725815/open-facebook-app-from-other-app) – n00bProgrammer

回答

1

您的網址應改爲使用URL方案代替,看看這些職位的完整細節,

http://wiki.akosma.com/IPhone_URL_Schemes#Facebook

Open a facebook link by native Facebook app on iOS

如果你試圖導航到一個頁面或個人資料,地址應如下,

NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"]; 
[[UIApplication sharedApplication] openURL:url]; 
+0

的可能重複我把數在後NSURL * url = [NSURL URLWithString:@「fb:// 」]; 「在這裏插入功能」,它只需要我到Facebook而不是應用程序的粉絲頁面! – user3580117

+0

應該是像fb:// profile/number,如果你想打開一個頁面或一個配置文件 – rustylepord

2

你可以做:

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

Schemes

FB://簡介 - 打開Facebook應用程序到用戶的個人資料

FB://朋友 - 打開Facebook應用程序的朋友列表

fb:// notifications - 打開Facebook應用程序到通知列表(注意:這個URL似乎有一個錯誤。通知頁面打開。然而,這不是可以導航到其他地方在Facebook的應用程序)

FB://飼料 - 打開Facebook應用程序的新聞訂閱

FB://事件 - 打開Facebook應用程序,以

的活動頁面

FB://請求 - 打開Facebook應用程序的請求列表

FB://筆記 - 打開Facebook應用程序的註釋頁面

FB://專輯 - 打開Facebook應用程序,以相冊列表

+1

* fb:// profile typo – n00bProgrammer

+1

感謝您的糾正。 –

0

您可以使用Apple URL schemes與其他應用程序進行通信。閱讀DOCS Communicating With Other Apps

打開Facebook應用使用fb: URL scheme;即

NSURL *url = [NSURL URLWithString:@"fb://https:facebook.com/NUMBER HERE"]; 
[[UIApplication sharedApplication] openURL:url]; 
相關問題