BarryK88
BarryK88

Reputation: 1806

How to take a screenshot in your App and publish it on facebook?

I'm trying to use facebook within my App by posting a screenshot of my App on my wall.

I already made the 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 for posting stuff on my facebook wall with an icon, title and small description.

- (void)postToWall {


    FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
    dialog.userMessagePrompt = @"Enter your message:";
    dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@ share's 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 of how to put my screenshot within the postToWall method? Thanks in advance!

Upvotes: 4

Views: 1303

Answers (2)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

It seems like you can't do this completely via Facebook. You should look at photo sharing sites for this. First upload your image to that site and get the link. Then share it via this method.

Edit
I am not saying the photo upload isn't possible. It just isn't possible to post a photo to the wall along with a link to your app without uploading it first.

Upvotes: 1

YuzaKen
YuzaKen

Reputation: 136

Using Facebook's SDK for iPhone, it is possible. You will need to construct and argument block (NSDictionary) and send that to the your validated Facebook session.

In the snippet here, "session" is of type Facebook * defined in Facebook.h of the 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];

Upvotes: 1

Related Questions