在 IOS 上使用 FBSDKShareKit 分享照片和链接

问题描述 投票:0回答:1

我正在使用 FBSDKShareKit 在 Facebook 上分享链接和图像 我遇到一个问题,当我只分享照片时它工作正常,但是当我同时分享链接和照片时它只能分享链接,而不是照片。

这是代码

 let content = SharePhotoContent()
               content.photos = sharePhotos
               content.contentURL = url
               content.hashtag = Hashtag("#Hapufood")
               // Hiển thị dialog chia sẻ
               let dialog = ShareDialog(viewController: UIApplication.shared.keyWindow?.rootViewController, content: content, delegate: nil)
               dialog.show()

请帮我解决这个问题。谢谢

ios swift facebook share
1个回答
0
投票

要使用 FBSDKShareKit 同时共享链接和照片,您应该使用 ShareLinkContent 而不是 SharePhotoContent。 ShareLinkContent 允许您指定要共享的 URL 和照片。

以下是如何修改代码来实现此目的:

let content = ShareLinkContent()
content.contentURL = url
content.hashtag = Hashtag("#Hapufood")
content.imageURL = imageURL // Specify the URL of the image you want to share

// Display the share dialog
let dialog = ShareDialog(viewController: UIApplication.shared.keyWindow?.rootViewController, content: content, delegate: nil)
dialog.show()

在此代码片段中,imageURL 表示您想要与链接一起共享的图像的 URL。您需要在 contentURL 旁边提供要共享的图像的 URL。

确保您在 Facebook 应用程序设置中配置了适当的权限来共享照片链接。此外,请确保您尝试共享的图像可访问且格式正确,以便在 Facebook 上共享。

© www.soinside.com 2019 - 2024. All rights reserved.