这个问题与iOS 4.0 设备上的 Facebook SDK for iOS非常相似,但由于我无法在那里发表评论,因此我提出了一个新问题。我认为问题不一样:
当尝试将我的应用程序的 facebook 集成更新到 facebook 3.1 时,我没有让 facebook 会话打开 sessionStateChanged 回调总是以 FBSessionStateClosedLoginFailed 结束。在我的设置中,我的 appdelegate 中有回调
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
// return [self.session handleOpenURL:url];
return [FBSession.activeSession handleOpenURL:url];
}
但它永远不会被调用!它不应该被调用吗?我遵循了 facebook 文档并致电
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions", nil];
return [FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
我也试过
openActiveSessionWithReadPermissions
使用nil
facebook 教程示例中的权限,以便稍后重新授权 publish_actions 权限。同样的结果: FBSessionStateClosedLoginFailed 再次。
我什至试着打电话
ACAccountStore *accountStore;
ACAccountType *accountTypeFB;
if ((accountStore = [[ACAccountStore alloc] init]) &&
(accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){
NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
id account;
if (fbAccounts && [fbAccounts count] > 0 &&
(account = [fbAccounts objectAtIndex:0])){
[accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
//we don't actually need to inspect renewResult or error.
if (error){
}
}];
}
}
在尝试打开会话之前,但我从来没有在我的 ios6 设备(iphone 4s)上打开它。在应用程序中,我被要求获得许可,但由于会话始终处于 FBSessionStateClosedLoginFailed 状态,因此什么也没有发生!我对会话状态的回调是
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"User session found");
}
break;
case FBSessionStateClosed:
NSLog(@"FBSessionStateClosed");
case FBSessionStateClosedLoginFailed:
NSLog(@"FBSessionStateClosedLoginFailed");
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"facebook Hinweis"
message:@"facebook Login nicht möglich, bitte versuchen Sie es erneut."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Facebook session error: %@", error.localizedDescription);
}
}
在 ios 5 上使用 facebook 3.0 我从来没有遇到过问题,所以我的 facebook 应用程序设置正确。我真的很感激任何帮助让我能够打开 facebook 会话,没想到会遇到 facebook 3.1 的这些问题,而且文档在这一点上没有帮助我,谢谢