FBSDKGraphRequest in a bolt structure never calls a 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; }]; 

FBSDKGraphRequest works fine outside of the Bolts task, but startWithCompletionHandler does not start inside the task.

Any ideas?

+7
ios bolts-framework
source share
3 answers

I found a workaround. Just wrap it in the 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]; }]; }); 
+20
source share

We had the exact same problem and we used the same solution, but I can not find any messages explaining why this is happening.

+2
source share

I ran into the same problem. It seems that PFFacebookUtils executes its continuation block in another thread, but it seems that FBSDKGraphRequest is expecting it to be launched from the main thread. I found that the problem can be solved by specifying the artist.

 BFTask* loginTask = [PFFacebookUtils logInInBackgroundWithReadPermissions:@[]]; [loginTask continueWithExecutor:[BFExecutor mainThreadExecutor] withSuccessBlock:^id _Nullable(BFTask * _Nonnull task) { FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]; [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { // This code gets called properly }]; }]; 
+2
source share

All Articles