分享静态照片时,我可以让我的应用切换到 Facebook 以分享该图像。它似乎与视频不一样。
这分享了一张照片就好了。它移动到 Facebook 应用程序以确认该帖子:
let sharePhoto = FBSDKSharePhoto()
sharePhoto.image = photo
let content = FBSDKSharePhotoContent()
content.photos = [sharePhoto]
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = content
shareDialog.mode = .native
shareDialog.show()
同样,共享视频时我不能这样做!没有对话,不切换到 Facebook 应用程序,也不发布视频:
let shareVdo: FBSDKShareVideo = FBSDKShareVideo()
shareVdo.videoURL = self.fileURL
let vdoContent = FBSDKShareVideoContent()
vdoContent.video = shareVdo
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = vdoContent
shareDialog.mode = .native
shareDialog.show()
这将分享我的视频,但立即没有对话,或者首先转移到 Facebook 应用程序!
let shareVdo: FBSDKShareVideo = FBSDKShareVideo()
shareVdo.videoURL = self.fileURL
let vdoContent = FBSDKShareVideoContent()
vdoContent.video = shareVdo
FBSDKShareAPI.share(with: vdoContent, delegate:self)
根据文档,我可能需要将我的 fileURL 转换为资产 URL。我不清楚是否应该使用 FBSDKShareAPI:
let shareVdo: FBSDKShareVideo = FBSDKShareVideo()
let asset = AVAsset(url: self.fileURL)
let assetURL = self.getAssetUrl(asset:asset)
shareVdo.videoURL = assetURL
let vdoContent = FBSDKShareVideoContent()
vdoContent.video = shareVdo
//FBSDKShareAPI.share(with: vdoContent, delegate:self)
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = vdoContent
shareDialog.mode = .native
shareDialog.show()
如果我取消注释 FBSDKShareAPI.share 函数调用,我会在我的控制台中看到“TIC 读取状态”,它最终会发布到 Facebook,但不会显示本机共享对话框。(基本上它在没有任何视觉反馈给用户的情况下无形地分享给 Facebook)。我希望它移动到 Facebook 应用程序,内容需要用户确认,就像在我的应用程序中共享照片一样。
另一种尝试是使用带有初始化参数“videoURL”和“previewPhoto”的FBSDKShareVideo。我确保视频小于 12 兆字节(在我的情况下为 4.4 MB),sharePhoto 和那个 fileURL 都是有效的。共享对话框不起作用,这意味着它不会转移到本机 Facebook 应用程序中。Facebook 开发人员指南使用 imagePickerController 显示它,这可能意味着 SDK 需要来自相机胶卷的视频。
let photo = self.uiImages[0]
let sharePhoto = FBSDKSharePhoto()
sharePhoto.image = photo
let filePath = self.fileURL
// get size of video in bytes
do {
var fileSize : UInt64
let attr = try FileManager.default.attributesOfItem(atPath: (filePath?.path)!)
fileSize = attr[FileAttributeKey.size] as! UInt64
print(fileSize)
} catch {
print("Error: \(error)")
}
let shareVideo = FBSDKShareVideo(videoURL: self.fileURL, previewPhoto: sharePhoto)
let content = FBSDKShareVideoContent()
content.video = shareVideo
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = content
shareDialog.mode = .native
shareDialog.show()