2012-10-20 20 views

Antwort

24

Dies ist die einfachste Art, wie ich

- (void) postImageToFB:(UIImage*)image 
{ 
    NSData* imageData = UIImageJPEGRepresentation(image, 90);  
    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
            @"This is my drawing!", @"message", 
            imageData, @"source", 
            nil]; 

    [FBRequestConnection startWithGraphPath:@"me/photos" 
           parameters:params 
           HTTPMethod:@"POST" 
          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 

          }]; 
} 

gefunden habe, wenn Sie auf einem Freund Wand zu stellen, ändern @"me/photos" von @"[friendID]/photos"

Dann fragen Sie nach Berechtigungen, die Methode zu veröffentlichen und rufen

if ([FBSession.activeSession.permissions indexOfObject:@"publish_stream"] == NSNotFound) 
{ 
    // No permissions found in session, ask for it 
    [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_stream"] 
               defaultAudience:FBSessionDefaultAudienceFriends 
              completionHandler:^(FBSession *session, NSError *error) 
    { 
     // If permissions granted, publish the story 
     if (!error) [self postImageToFB:currentDrawing]; 
    }]; 
} 
// If permissions present, publish the story 
else [self postImageToFB:currentDrawing]; 

Ein "[App Name] Fotos" Album erstellt wird, existiert, wenn nicht

Es funktioniert für mich!

+4

keine Notwendigkeit NSData, es nur als UIImage speichern und das Bild Taste als „Bild“ ändern, Graph API wird den Rest erledigen :-) –

+0

Ihre Komprimierung bei UIImageJPEGRepresentation sollte zwischen 0-1.0 sein .. also statt 90 Sie meinen .9 – badweasel

Verwandte Themen