2

如何將Facebook登錄整合到iOS應用中,適用於所有版本?iOS Facebook登錄教程

我沒有一個完整的解決方案,搜索Google和GitHub幾個小時。我還閱讀了Facebook上的所有文檔,並解析了ios-facebook示例代碼。我有一個適用於> = iOS6的工作版本,但低於此值的任何版本都會崩潰(ACAccountStore不存在)。目前我正在使用名爲LBFacebook的圖書館進行登錄。唯一的缺點是,它不適用於iOS5。

我拉我的頭髮。 FacebookSDK每隔幾周就會更改一次。如果能夠一勞永逸,這將是不可思議的。

+3

「所有版本」是什麼? iOS版? Facebook的?所有iPhone出貨*有史以來*? –

回答

5

Facebook SDK 3.1向後兼容。它試圖按以下順序進行身份驗證:

  1. 帳戶框架(ACAccount)
  2. 通過Facebook的應用程序(如果已安裝)
  3. 通過Web瀏覽器(老辦法)

我可以證實它在舊版iOS版本中可以正常工作。如果您收到ACAccountStore不存在的錯誤,則表示您的操作有誤。從文檔:

如果您還沒有登錄之前,根據您的iOS, 你會看到本機登錄模式對話框的版本,被重定向到 的Facebook的iOS或重定向到Facebook在Safari中完成 的認證流程。

請參閱here。他們展示了不同iOS版本的外觀。請參閱here

+0

謝謝!我終於能夠啓動並運行了。這一切都依賴於FBLoginView,直到我清理項目時纔出現。 – user2247438

2
NSString *strName= @"Mohit Thatai"; 
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 
    [login 
    logInWithReadPermissions: @[@"public_profile", @"email"] 
    handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
     if (error) 
     { 
      NSLog(@"Error"); 
     } 
     else if (result.isCancelled) 
     { 
      NSLog(@"Cancell"); 
     } 
     else 
     { 
    NSLog(@"Login Sucessfull"); 
// Share link text on face book 
     FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init]; 
      [content setContentTitle:@"GPS Tracker"]; 
      [content setContentDescription:[NSString stringWithFormat:@"%@ shared an interesting link\n  This might be interesting to you: GPS Tracker for Kids",strName]]; 
content.contentURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://gpsphonetrackerkids.com"]]; 
      [FBSDKShareDialog showFromViewController:self 
             withContent:content 
              delegate:nil]; 
     } 
    }];