Facebook iOS SDK 3.6 startWithGraphPath完成块未执行 [英] Facebook iOS SDK 3.6 startWithGraphPath completion block not executed

查看:65
本文介绍了Facebook iOS SDK 3.6 startWithGraphPath完成块未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与Facebook集成在一起,因此我可以将状态发布到我的提要中.我基于发布以供稿给开发人员教程.当从我的iOS应用程序运行以下Graph API请求时,将永远不会调用该请求的完成块,并且XCode调试日志中不会出现错误.

I've integrated with Facebook so that I can, among other things, post statuses to my feed. I based some of my code off of the publish to feed developer tutorial. When running the following Graph API request from my iOS application the completion block of the request is never called and no error appears in the XCode debug log.

[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    if (error) {
        DLog(@"error: domain = %@, code = %d", error.domain, error.code);
    } else {
        DLog(@"Posted action, id: %@", result[@"id"]);
    }
}];

我有两个便捷功能,可以在执行此请求之前针对当前的activeSession执行检查.他们看起来像这样:

I have two convenience functions that perform checks against the current activeSession before executing this request. They look like this:

+ (BOOL)facebookSessionIsOpen {
    return (FBSession.activeSession.isOpen);
}

+ (BOOL)facebookSessionHasPublishPermissions {
    if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound ||
        [FBSession.activeSession.permissions indexOfObject:@"publish_stream"] == NSNotFound ||
        [FBSession.activeSession.permissions indexOfObject:@"manage_friendlists"] == NSNotFound) {
        return NO;
    } else {
        return YES;
    }
}

这两个函数均返回YES,表示具有必要的发布许可的活动会话.更令人困惑的是,使用以下代码成功执行相同的检查后,我可以毫无问题地拉出用户的个人资料(无需授予许可的发布权限即可拉出个人资料):

Both of these functions return YES indicating an active session with the necessary publishing permission. What's more confusing is that I can pull the user's profile without issue after performing the same checks successfully (granted publishing permissions are not required to pull the profile) using the following code:

[FBRequestConnection
startWithGraphPath:@"me"
parameters:[NSDictionary dictionaryWithObject:@"picture,id,birthday,email,location,hometown" forKey:@"fields"]
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    NSDictionary* resultDict = (NSDictionary*)result;

    NSString* emailAddress = resultDict[@"email"];
    NSString* location = resultDict[@"location"][@"name"];
    NSString* birthday = resultDict[@"birthday"];
    NSString* homeTown = resultDict[@"hometown"][@"name"];
    ...
}];

关于如何调试此问题的任何建议?

Any suggestions on how to debug this issue?

推荐答案

原来是线程问题. Facebook iOS SDK似乎不喜欢在不同于您调用openActiveSessionWithReadPermissions的线程上执行FBRequest并立即死锁.事实证明,我正在像这样的单独线程中运行postStatus请求:

Turns out the issue was a threading one. The Facebook iOS SDK doesn't seem to like to execute a FBRequest on a different thread from the one that you called openActiveSessionWithReadPermissions on and promptly deadlocks. It turns out I was running the postStatus request in a separate thread like so:

dispatch_queue_t some_queue = dispatch_queue_create("some.queue.name", NULL);
dispatch_async(some_queue, ^{
    [FacebookHelper postStatusToFacebookUserWall:newStatus withImage:imageData];
}];

请确保您的openActiveSessionWithReadPermissions和所有FBRequest排列都发生在同一线程上,否则您很可能会遇到这些无声的故障.

Make sure your openActiveSessionWithReadPermissions and any FBRequest permutations all happen on the same thread, or you'll likely run into these silent failures.

这篇关于Facebook iOS SDK 3.6 startWithGraphPath完成块未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆