how to share screenshot to Facebook

310 views Asked by At

I've already done that screenshot part, but still haven't found any solution to share the screenshot image to Facebook by using FBSDKSharePhoto. Facebook doesn't provide enough references for it. Can anyone please guide me here?

Here is my screenshot code just in case:

CGRect screenRect = [[UIScreen mainScreen] bounds];

UIGraphicsBeginImageContextWithOptions(screenRect.size, NO , 0.0f);

CGContextRef ctx = UIGraphicsGetCurrentContext();

[[UIColor blackColor] set];

CGContextFillRect(ctx, screenRect);



UIWindow *window = [UIApplication sharedApplication].keyWindow;



[window.layer renderInContext:ctx];

UIImage *screengrab = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();
1

There are 1 answers

3
Colin Smillie On BEST ANSWER

I believe you want to FBSDKSharePhotoContent and FBSDKShareDialog. You need to setup your content as a photo(s):

UIImage *screengrab = UIGraphicsGetImageFromCurrentImageContext();
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[[FBSDKSharePhoto photoWithImage:screengrab userGenerated:YES]];

// Assuming self implements <FBSDKSharingDelegate> 
[FBSDKShareAPI shareWithContent:content delegate:self];