使用FB SDK v3.5在“允许这些应用程序使用您的帐户”列表中不显示iOS应用程序

我为我的应用程序使用FB ios SDK v3.5。 对于login部分,我不使用FBLoginView来login,而是使用UIButton并在该UIButton的处理程序中调用[FBSession openActiveSessionWithReadPermission]。

在FB SDK v3.2.1中,我使用下面的代码来处理不同的login情况,它工作正常:

self.useAccountAllowed = true; ACAccountStore *accountStore; ACAccountType *accountTypeFB; if ((accountStore = [[ACAccountStore alloc] init]) && (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){ NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB]; id account; if (!fbAccounts) { //do not log into FB on the device } else if ([fbAccounts count] == 0) { [FBSession.activeSession closeAndClearTokenInformation]; self.useAccountAllowed = false; //User does not allow the app to use the account } else if ([fbAccounts count]>0 && (account=[fbAccounts objectAtIndex:0])) { [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) { //User allowes the app to use the account //we don't actually need to inspect renewResult or error. if (error){ } }]; } } 

那么在UIButton的处理函数中:

 if (self.useAccountAllowed) { [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession* session, FBSessionState status, NSError* error){ [self sessionStateChanged:session state:status error:error];}]; } else { NSArray* lPermission = FBSession.activeSession.permissions; [FBSession openActiveSessionWithPermissions:lPermission allowLoginUI:YES completionHandler:^(FBSession* session, FBSessionState status, NSError* error){ [self sessionStateChanged:session state:status error:error];}]; 

这意味着如果用户不允许应用程序使用该帐户,我们只需通过Safari快速切换方式login; 否则我们使用本地login。

但是在SDK v3.5中,仍然是相同的代码,但有时当应用程序被执行并login到Facebook时,应用程序不在“允许这些应用程序使用您的帐户”列表中,因此此代码无法区分这两种情况: 1.该应用程序不在列表中; 2.用户不允许该应用使用此帐户。 所以应用程序无法本地login。

注意这个问题是随机存在的。 有时我硬编码直接调用openActiveSessionWithPermissions,这个问题就没有了。 但是我不确定是什么原因。

我只是想在FB SDK v3.5中,我是否需要显式地调用一些与iOS设置相关的SDK函数?