使用 Swift 将 UIImage 直接添加到 FBSDKShareLinkContent 中?
Add UIImage directly into FBSDKShareLinkContent with Swift?
我有 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)
}
问题是我没有图像URL,我有一张直接从应用程序的相机功能中拍摄的图像,存储为 UIImage 变量。如何在没有在线托管图像的情况下将图像附加到此 FBSDKShareLinkContent?我正在使用 FBSDKShareLinkContent,因为我还共享了一个 link w/ title & description。
编辑,我正在尝试使用此代码的 FBSDKSharePhoto(正如有人建议的那样),它可以让我 post 照片,但我无法将 URL 转换为 link即使 content.contentURL
的定义与之前一样,也是正确的。
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 知道有一个错误,导致图像和 link 无法协同工作。
https://developers.facebook.com/bugs/949486035103197/
他们说这应该在下一个 Facebook 应用程序更新 v31 中更新。 v30 已于 5 月 7 日更新,FB 每两周发布一次更新,所以我会在一周后回来查看并确认功能已修复。
我有 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)
}
问题是我没有图像URL,我有一张直接从应用程序的相机功能中拍摄的图像,存储为 UIImage 变量。如何在没有在线托管图像的情况下将图像附加到此 FBSDKShareLinkContent?我正在使用 FBSDKShareLinkContent,因为我还共享了一个 link w/ title & description。
编辑,我正在尝试使用此代码的 FBSDKSharePhoto(正如有人建议的那样),它可以让我 post 照片,但我无法将 URL 转换为 link即使 content.contentURL
的定义与之前一样,也是正确的。
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 知道有一个错误,导致图像和 link 无法协同工作。
https://developers.facebook.com/bugs/949486035103197/
他们说这应该在下一个 Facebook 应用程序更新 v31 中更新。 v30 已于 5 月 7 日更新,FB 每两周发布一次更新,所以我会在一周后回来查看并确认功能已修复。