我有 FBSDK 共享功能,使用以下代码:
if (FBSDKAccessToken.currentAccessToken() != nil) {
// User is already logged in, do work such as go to
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: self.url_string)
content.contentTitle = self.title_text
content.contentDescription = self.desc_text
content.imageURL = NSURL(string: "http://image.png")
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 30)
button.center = self.view.center
self.view.addSubview(button)
}
问题是我没有 imageURL,我有一张直接从应用程序的相机功能拍摄的图像,存储为 UIImage 变量。如何在没有在线托管图像的情况下将图像附加到此 FBSDKShareLinkContent?我正在使用 FBSDKShareLinkContent,因为我还共享了一个带有标题和描述的链接。
编辑,我正在尝试使用此代码的 FBSDKSharePhoto(正如有人建议的那样),这让我可以发布照片,但即使 content.contentURL
是,我也无法正确链接 URL定义如前。
let photo : FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = self.scaledImage
photo.userGenerated = true
let content : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
content.contentURL = NSURL(string: self.url_string)
content.photos = [photo]
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 30)
button.center = CGPointMake(self.view.center.x, self.descLabel.center.y + 51 + 30) // 51 = 1/2 of height of descLabel, 30 = space below
self.view.addSubview(button)
最佳答案
看来 FBSDKSharePhotoContent
是可行的方法,但目前 Facebook 发现了一个错误,导致图像和链接无法协同工作。
https://developers.facebook.com/bugs/949486035103197/
他们说这应该在下一个 Facebook 应用程序更新 v31 中更新。 v30 已于 5 月 7 日更新,FB 每两周发布一次更新,因此我将在一周后回来查看并确认功能已修复。
关于ios - 使用 Swift 将 UIImage 直接添加到 FBSDKShareLinkContent 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30279139/