gpt4 book ai didi

ios - Facebook iOS SDK 3.1 在后续调用 FBSession openWithBehavior 时崩溃

转载 作者:可可西里 更新时间:2023-11-01 03:30:48 26 4
gpt4 key购买 nike

如果我们在调用 closeAndClearTokenInformation 之后调用 openWithBehavior,它会导致 EXC_BAD_ACCESS。无论是使用 native iOS 内置对话框还是快速切换对话框之一。

我们登录 FB 的代码,第一次通过作品:

if (![FBSession activeSession]) {
#ifdef FREE_APP
NSString* suffix = @"free";
#else
NSString* suffix = @"paid";
#endif
FBSession *session = [[[FBSession alloc] initWithAppID:@"111111111111111"
permissions:permissions
urlSchemeSuffix:suffix
tokenCacheStrategy:nil] autorelease];
[FBSession setActiveSession:session];
}
else if ([FBSession activeSession].isOpen)
[[FBSession activeSession] close];

[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];

我们注销的代码,之后上面的代码在 openWithBehavior 后失败:

[[FBSession activeSession] closeAndClearTokenInformation];

我最初使用的是 openActiveSessionWithReadPermissions 而不是 openWithBehavior,如 3.1 文档中所述,它不会崩溃,但应用程序从 FB 应用程序/Safari 切换回来不起作用。也许是因为需要有一个后缀?如果修复应用程序切换并返回到那个最简单,请告知。

谢谢。

最佳答案

当我在 5.x 模拟器中运行时,我看到了一条来自 openWithBehavior 的额外的、非常有用的错误消息,然后在源代码中查找它,这让事情变得更加清晰:

if (!(self.state == FBSessionStateCreated ||
self.state == FBSessionStateCreatedTokenLoaded)) {
// login may only be called once, and only from one of the two initial states
[[NSException exceptionWithName:FBInvalidOperationException
reason:@"FBSession: an attempt was made to open an already opened or closed session"
userInfo:nil]
raise];
}

我更改了我的代码以始终在调用 openWithBehavior 之前创建一个新 session ,这看起来很开心。

更新:这是更新后的代码,用于检查事件 session ,然后关闭它,然后始终实例化新 session ...

  - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {


if ([FBSession activeSession])
[[FBSession activeSession] closeAndClearTokenInformation];

#ifdef FREE_APP
NSString* suffix = @"free";
#else
NSString* suffix = @"paid";
#endif

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];

FBSession *session = [[FBSession alloc] initWithAppID:mFacebookID
permissions:permissions
urlSchemeSuffix:suffix
tokenCacheStrategy:nil];

[FBSession setActiveSession:session];

If (allowLoginUI == YES) {
NSLog(@"Calling openWithBehavior");
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
[self sessionStateChanged:session state:state error:error];
}
];
} else if(session.state == FBSessionStateCreatedTokenLoaded) {
NSLog(@"Calling openWith completion handler");
[session openWithCompletionHandler:^(FBSession *_session, FBSessionState status, NSError *error)
{ [self sessionStateChanged:session state:status error:error];}
];
}

[session release];

return true;
}

关于ios - Facebook iOS SDK 3.1 在后续调用 FBSession openWithBehavior 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13228700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com