I managed to implement Facebook connect on my iPhone app and allow the user to upload a status update via the app. I now want to include a feature to allow uploading of phot
This following snippet is taken from the facebook-ios-sdk. Assuming your class already has a facebook object, this method will upload a photo from a URL (change as needed):
-(IBAction) uploadPhoto: (id)sender {
NSString *path = @"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture",
nil];
[facebook requestWithMethodName: @"photos.upload"
andParams: params
andHttpMethod: @"POST"
andDelegate: self];
[img release];
}
In order to send a caption with the photo you must add the "message" parameter key followed by the caption text. Changing params
like below should achieve this:
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, @"picture",
@"my photo's caption text here.", @"message"
nil];
You can upload photo by using iOS Facebook SDK as follows:
FBSDKSharePhoto *photo=[[FBSDKSharePhoto alloc]init];
photo.image=slideImage;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
This works only if you configure iPhone Facebook settings.