我有以下代码:
[[[PFFacebookUtils logInInBackgroundWithAccessToken:[FBSDKAccessToken currentAccessToken]] continueWithSuccessBlock:^id(BFTask *task) { PFUser *user = task.result; return user; }] continueWithSuccessBlock:^id(BFTask *task) { BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource]; FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraPHPath:@"me" parameters:nil]; [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,id result,NSError *error) { if (error) { [source setError:error]; return; } [source setResult:result]; }]; return source.task; }];
FBSDKGraphRequest在Bolts任务之外工作正常,但在任务内部没有调用startWithCompletionHandler.
有任何想法吗?
解决方法
我找到了解决方法.只需将其包装在主线程块中即可.它会像魅力一样工作.
dispatch_async(dispatch_get_main_queue(),^{ FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraPHPath:@"me" parameters:nil]; [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,NSError *error) { if (error) { [source setError:error]; return; } [source setResult:result]; }]; });