How to take a screenshot in my application and publish it on facebook?

I am trying to use facebook in my application by posting a screenshot of my application on my wall.

I already made functions for taking a screenshot

UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

and to publish materials on my facebook wall with an icon, title and a small description.

 - (void)postToWall { FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease]; dialog.userMessagePrompt = @"Enter your message:"; dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@ share a photo\",\"href\":\"mywebsite.com/\",\"caption\":\"%@thinks this is a nice photo\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"mywebsite.com/icon.png\",\"href\":\"mywebsite.com/\"}]}", _facebookName, _facebookName]; dialog.actionLinks = @"[{\"text\":\"Get My App\",\"href\":\"http://itunes.apple.com//\"}]"; } 

Any suggestions on how to put my screenshot in the postToWall method? Thanks in advance!

+4
source share
2 answers

Using the Facebook SDK for iPhone is possible. You will need to build a block and an argument block (NSDictionary) and send it to your trusted Facebook session.

In this snippet, a β€œsession” is of the Facebook * type defined in the Facebook.h SDK.

 NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease]; [args setObject:captionText forKey:@"caption"]; [args setObject:messageText forKey:@"message"]; [args setObject:UIImageJPEGRepresentation(yourImage, 0.7) forKey:@"picture"]; [session requestWithMethodName:@"photos.upload" andParams:args ndHttpMethod:@"POST" andDelegate:self]; 
+1
source

It looks like you cannot do this completely through Facebook. To do this, you should look at sites for sharing photos. First upload your image to this site and get a link. Then share it using this method.

Edit
I am not saying that downloading photos is not possible. It is simply impossible to send a photo to the wall with a link to your application without first loading it.

+1
source

All Articles