在使用图片发布到Facebook之前,我使用了以下代码来捕获屏幕截图:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(frame.size.width,frame.size.height), false, 0)
self.view?.drawViewHierarchyInRect(CGRectMake(-frame.origin.x, -frame.origin.y, view.bounds.size.width, view.bounds.size.height), afterScreenUpdates: false)
let screenShot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return screenShot在第一个实例中,我使用了Social Framework和SLComposeViewController,使用addImage添加了屏幕截图。对话框上的图像和最终的帖子都很完美,但这种方法不允许你选择朋友。
然后我决定使用use FBSDKDialog,如下所示:
let photo : FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = screenShot
photo.userGenerated = false
photo.caption = contentDescription
let photoContent : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
photoContent.photos = [photo]
photoContent.contentURL = NSURL(string: self.contentURL)
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = self
shareDialog.shareContent = photoContent
shareDialog.delegate = self
if !shareDialog.canShow() {
shareDialog.mode = FBSDKShareDialogMode.Native
} else {
shareDialog.mode = FBSDKShareDialogMode.FeedBrowser
}
shareDialog.show()代码运行良好,但“共享”对话框上的图像质量极差。然而,当我发布帖子时,时间线上的图像质量是完美的。
我试着压缩图像,但似乎没有什么不同。有人能指出我做错了什么吗?谢谢。
发布于 2015-11-14 07:38:02
你没做错什么。这可能是Facebook优化分享的一种方式。
https://stackoverflow.com/questions/33497411
复制相似问题