0

ich diese LogikTeilen Fotos funktioniert nicht, wenn der Benutzer zuvor Facebook angemeldet ist

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

Wenn der Benutzer in Facebook zuvor angemeldet ist, wird die Anfrage ein Foto zu teilen ist in der Schwebe verloren. Eingabe der Bibliothek wurde mir klar, dass diese Funktion _sharePhotoContent y tritt stirbt rechts in dieser Zeile FBSDKGraphRequestHandler completionHandler =^(FBSDKGraphRequestConnection * connection, id result, NSError * error) {

ich denke, fällt nichts vernünftig, dass dies der Fall verursachen können.

Ich weiß nur, dass wenn ich versuche, das gleiche mit einem Benutzer ohne Sitzung (für den else) funktioniert perfekt zu tun.

Antwort

0

das Problem gefunden.

Ich rief Share-Logik in

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0), ^{ 

}); 

So müssen in Haupt-Thread ruft

dispatch_async(dispatch_get_main_queue(), ^{ 
    [self sharePhotoWithFBSDK:title andImage:image]; 
}); 
Verwandte Themen