我正在为我的应用使用FB ios SDK v3.5。对于登录部分,我不使用FBLoginView登录,而是使用UIButton并在该UIButton的处理程序中调用[FBSession openActiveSessionWithReadPermission]。
在FB SDK v3.2.1中,我使用以下代码处理不同的登录方案,它工作正常:
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登录;否则我们使用本机登录。
但是在SDK v3.5中,仍然是相同的代码,但有时当应用程序执行并登录到Facebook时,应用程序不在“允许这些应用程序使用您的帐户”列表中,因此此代码无法区分这些两种情况:1。应用程序不在列表中; 2.用户不允许该应用使用此帐户。所以应用程序无法以原生方式登录。
请注意,此问题是随机存在的。有时我硬代码直接调用openActiveSessionWithPermissions,这个问题就消失了。但我不确定是不是原因。
我只是想知道在FB SDK v3.5中,我是否需要显式调用一些与iOS设置相关的SDK功能?