在使用图像发布到 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
添加屏幕截图。对话框中的图像和最终帖子都很完美,但这种方法不允许您选择您的 friend 。
然后我决定使用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()
代码运行完美,但共享对话框上的图像质量极差。然而,当我发布帖子时,时间线上的图像质量是完美的。
我尝试过压缩图像,但似乎没有任何区别。 谁能建议我做错了什么? 谢谢。
最佳答案
你没有做错任何事。这可能是 Facebook 优化共享的一种方式。
关于ios - FBSDKshareDialog 和 FBSDKsharephoto 导致图像质量下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33497411/