how - ios 11 change photo album cover




IOS Facebook SDK 3 upload image with message (2)

Here is an example that posts and image and a note:

http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/

I am using the following code to upload an image to Facebook wall :

UIImage *img = [UIImage imageNamed:@"logoits.png"];

[FBRequestConnection startForUploadPhoto:img
                       completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

    NSLog(@"Facebook posting %@",result);
    NSLog(@"Facebook posting %@",error);

}];  

It works as expected but I would like to add a message or title to this uploaded photo, and looking at the documentation of FBRequestConnection there is no example of that. http://developers.facebook.com/docs/sdk-reference/iossdk/3.0/class/FBRequestConnection/

How do I upload an image with message?


In the Facebook SDK 3.0 only a image can be post using the given methods, and for other actions you need to use graph a pi's.

So for post a image with message you need to use graph-api. Here is the line of codes which lets you to post a image with message on users timeline.

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"your custom message" forKey:@"message"];
[params setObject:UIImagePNGRepresentation(_image) forKey:@"picture"];
_shareToFbBtn.enabled = NO; //for not allowing multiple hits

[FBRequestConnection startWithGraphPath:@"me/photos"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection,
                                              id result,
                                              NSError *error) 
 {
     if (error) 
     {
         //showing an alert for failure
         [self alertWithTitle:@"Facebook" message:@"Unable to share the photo please try later."];
     } 
     else
     {
         //showing an alert for success
         [UIUtils alertWithTitle:@"Facebook" message:@"Shared the photo successfully"];
     }
     _shareToFbBtn.enabled = YES;
 }];

and also make sure _shareToFbBtn is enabled only after login is success.