Reputation: 4279
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"]);
}
}];
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;
}
}
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?
Upvotes: 3
Views: 4573
Reputation: 4279
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];
}];
Make sure your openActiveSessionWithReadPermissions
and any FBRequest
permutations all happen on the same thread, or you'll likely run into these silent failures.
Upvotes: 5