ios - 使用 Swift 将 UIImage 直接添加到 FBSDKShareLinkContent 中?

标签 ios facebook swift uiimage

我有 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/

相关文章:

php - Composer 自动加载+ facebook sdk

ios - 当我们在 swift iOS 的 UIWebView 上有一些内容时,如何获得正确的高度?

ios - 在显示之前更改 UIActionsheet 按钮文本和背景

ios - UIImagePickerController 和 iCloud 照片

ios - 从 mapView.annotations 访问 MKAnnotationView

ios - Facebook SDK 更新 - 缓存访问 token 问题

ios - 无法使用 ideviceinstaller 或 fruitstrap 安装开发人员认证的 iOS 应用程序

java - 如何为键可变的 JSON 字符串创建 java 类?

ios - Swift - 如何在自定义 AlertController 中点击按钮时呈现 ViewController

swift - 如何检查当前是否在 Swift 中按下了 shift 键?