简体   繁体   English

facebook ios sdk 3.1.1 FBSession completionHandler未删除

[英]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.

相关问题 在Facebook iOS 3.1.1 SDK中使用FBSession openActiveSessionWithReadPermissions处理无效的accessToken - Handle invalid accessToken with FBSession openActiveSessionWithReadPermissions in Facebook iOS 3.1.1 SDK Facebook iOS SDK,FBSession异常,***断言失败 - [FBSession close] - Facebook iOS SDK , exception against FBSession, *** Assertion failure in -[FBSession close] Facebook iOS SDK 4.x中没有FBSession - No FBSession in Facebook iOS SDK 4.x Facebook SDK 3.1.1,iOS 6,FBNativeDialogs - Facebook sdk 3.1.1, ios 6, FBNativeDialogs iOS –从facebook.com删除应用程序后,不显示Facebook SDK 3.1.1访问警报 - iOS – Facebook SDK 3.1.1 access alert doesn't show after app is removed from facebook.com FaceBook SDK,FBSession操作 - FaceBook SDK, FBSession actions FB ios SDK-3.0+-如何为[FBSession.activeSession openWithBehaviour:completedHandler]添加权限? - FB ios SDK - 3.0+ - How can I add permission to [FBSession.activeSession openWithBehaviour: completionHandler]? Facebook iOS SDK 3.1在随后调用FBSession openWithBehavior时崩溃 - Facebook iOS SDK 3.1 crashes on subsequent call to FBSession openWithBehavior Facebook iOS SDK 3.0登录教程问题与FBSession - Facebook iOS SDK 3.0 Login Tutorial Issue with FBSession Facebook IOS SDK 3.1.1与Xcode 4.5.2错误 - Facebook IOS SDK 3.1.1 with Xcode 4.5.2 error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM