I have this logic
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
NSLog(@"has granted!");
[self sharePhotoWithFBSDK:title andImage:image]; //for logged users
} else {
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
NSLog(@"response logInWithPublishPermissions!!! %@",error);
if (!error) {
[self sharePhotoWithFBSDK:title andImage:image]; //Non logged users
}
}];
}
- (void)sharePhotoWithFBSDK:(NSString *)title andImage:(UIImage *)image
{
FBSDKSharePhoto *sharePhoto = [[FBSDKSharePhoto alloc] init];
sharePhoto.caption = title;
sharePhoto.image = image;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[sharePhoto];
[FBSDKShareAPI shareWithContent:content delegate:self];
}
When the user is logged into facebook previously, the request to share a photo is lost in limbo. Entering the library I realized that enters this function _sharePhotoContent
y dies right in this lineFBSDKGraphRequestHandler completionHandler = ^ (FBSDKGraphRequestConnection * connection, id result, NSError * error) {
i can not think of anything reasonable that may be causing this occurs.
I only know that when I try to do the same with a user without session (for the else) works perfect.
Found the problem.
I was calling share logic into
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0), ^{
});
So, need calling in main thread
dispatch_async(dispatch_get_main_queue(), ^{
[self sharePhotoWithFBSDK:title andImage:image];
});