Facebook iOS SDK 3.6 startWithGraphPath完成块未执行

我已经与Facebook集成,因此除其他外,我可以将状态发布到我的Feed中。 我基于发布的一些代码来提供开发人员教程 。 从我的iOS应用程序运行以下Graph API请求时,永远不会调用请求的完成块,并且XCode调试日志中不会出现错误。

[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执行检查。 它们看起来像这样:

 + (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表示具有必要发布权限的活动会话。 更令人困惑的是,在使用以下代码成功执行相同检查(不需要授予发布权限来提取配置文件)后,我可以毫无问题地提取用户的配置文件:

 [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"]; ... }]; 

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

事实certificate这个问题是一个线程问题。 Facebook iOS SDK似乎不喜欢在与您调用openActiveSessionWithReadPermissions并且立即死锁的线程不同的线程上执行FBRequest 。 事实certificate我在一个单独的线程中运行postStatus请求,如下所示:

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

确保您的openActiveSessionWithReadPermissions和任何FBRequest排列都发生在同一个线程上,否则您可能会遇到这些静默失败。