Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FBSDKGraphRequest in a bolts framework never calls block

I have the following code:

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

The FBSDKGraphRequest works fine outside of the Bolts task, but inside the task the startWithCompletionHandler is not being called.

Any ideas?

like image 723
Scott McKenzie Avatar asked May 14 '15 10:05

Scott McKenzie


2 Answers

I found a workaround. Just wrap it within a main thread block. It will work like a charm.

dispatch_async(dispatch_get_main_queue(), ^{
    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];
    }];
});
like image 91
yuhua Avatar answered Oct 05 '22 23:10

yuhua


We had the same exact issue and we used the same solution but I can not seem to find any posts which explain why this is happening.

like image 32
Constantine Avatar answered Oct 05 '22 23:10

Constantine