如何将屏幕截图分享到 Facebook

how to share screenshot to Facebook

我已经完成了屏幕截图部分,但仍然没有找到任何使用 FBSDKSharePhoto 将屏幕截图图像共享到 Facebook 的解决方案。 Facebook 没有提供足够的参考资料。谁能在这里指导我?

为了以防万一,这是我的截图代码:

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();

我相信你想要 FBSDKSharePhotoContent 和 FBSDKShareDialog。您需要将您的内容设置为照片:

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

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