[英]facebook ios sdk 3.1.1 FBSession completionHandler not removed
When I open the Facebook session everything goes fine and the completion block gets called. 当我打开Facebook会话时,一切都很顺利,完成块被调用。
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
NSLog(@"openSession handler");
}];
But later when I ask for extra permissions for example, both completion blocks get called not only the new one. 但是后来当我要求额外的权限时,两个完成块不仅被调用,而且还被调用。
[FBSession.activeSession reauthorizeWithReadPermissions:
[NSArray arrayWithObject:@"user_photos"]
completionHandler:^(FBSession *session, NSError *error) {
NSLog(@"reauthorize handler");
}];
Is this a bug or is it supposed to be like this? 这是一个错误还是它应该是这样的? How can I avoid this behaviour? 我该如何避免这种行为? Is it possible to delete the completion block after the call? 是否可以在通话后删除完成块?
I looked into the Scrumptious sample and the behaviour is exactly the same. 我查看了Scrumptious样本,行为完全相同。 When the app asks for publish permissions the publish-completion block gets called and the login block gets called again. 当应用程序请求发布权限时,将调用发布完成块并再次调用登录块。
I'm testing on iOS5 and Facebook-ios-sdk 3.1.1 我正在测试iOS5和Facebook-ios-sdk 3.1.1
From what I could gather from Facebook's documentation in the API, this is an intended behaviour (not good design IMHO but that's another story). 从我从API的API文档中收集到的,这是一个预期的行为(不是好的设计恕我直言,但这是另一个故事)。
Snippet in the description of the completionHandler param: 在completionHandler参数的描述中的片段:
"...the FBSession object will call the block each time the session changes state" “......每次会话改变状态时,FBSession对象都会调用该块”
I can't offer you a fix, but I can offer a workaround: 我无法为您提供解决方案,但我可以提供解决方法:
// <Your description of why the workaround is needed.
//
// REF: http://stackoverflow.com/questions/12751635/facebook-ios-sdk-3-1-1-fbsession-completionhandler-not-removed
//
__block BOOL workaroundOneTimeRunFlag = NO;
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
if (!workaroundOneTimeRunFlag)
{
workaroundOneTimeRunFlag = YES;
// Your handler was executed for the first time
// Run some code...
}
}];
This is not a bug, and both handlers are intentionally called by the SDK. 这不是一个错误,SDK会有意调用这两个处理程序。 As noted in the docs , the handler to the openActiveSession is called whenever a session state change occurs. 如文档中所述,只要发生会话状态更改,就会调用openActiveSession的处理程序。 Asking for extra permissions will change the state to FBSessionStateTokenExtended; 要求额外的权限会将状态更改为FBSessionStateTokenExtended; therefore, the first handler gets called, and then the explicit handler you provide in the reauthorizeWithReadPermissions: 因此,第一个处理程序被调用,然后是你在reauthorizeWithReadPermissions中提供的显式处理程序:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.