2012-10-20 17 views

उत्तर

24

यह सबसे आसान तरीका मैं

- (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) { 

          }]; 
} 

पाया है कि आप प्रकाशित करें और विधि कॉल करने के लिए, एक दोस्त की दीवार पर पोस्ट तो @"[friendID]/photos"

द्वारा @"me/photos" बदलने के लिए, अनुमतियां मांगेंगे चाहते हैं

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

एक "[ऐप्लिकेशन नाम] फ़ोटो" एल्बम में बनाया जाएगा, यदि मौजूद नहीं है

यह मेरे लिए काम करता है!

+4

NSData की कोई जरूरत नहीं, बस एक UIImage के रूप में सहेज और के रूप में "तस्वीर" छवि कुंजी बदलने के लिए, ग्राफ एपीआई बाकी को संभालेगा :-) –

+0

UIImageJPEGRresentresent पर आपका संपीड़न 0-1.0 के बीच होना चाहिए .. तो 90 के बजाय आपका मतलब है। 9 – badweasel