Question

I have an app where I save the current view as an image using the following code:

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
savedImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Now I want to be able to post this image to Facebook. I have the following code:

if([SLComposeViewController isAvailableForServiceType: SLServiceTypeFacebook]) {

        slComposeView = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        [slComposeView addImage: [UIImage imageNamed:savedImg]];
        [self presentViewController:slComposeView animated:YES completion:NULL];
}

Obviously this is wrong because I cannot pass UIImage to an NSString. What is the correct way to do it?

Was it helpful?

Solution

Get rid of the imageNamed call and pass the savedImg variable directly into the addImage call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top