0

I am using FBSDKShareKit to share link and images on Facebook. When I share only photos it works fine, but when I share a link and photos at the same time it can only share the link, not the photos.

Here is the code:

let content = SharePhotoContent()

content.photos = sharePhotos
content.contentURL = url
content.hashtag = Hashtag("#Hapufood")

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

Please help me solve this problem.

1 Answer 1

0

To share both a link and photos simultaneously using FBSDKShareKit, you should use ShareLinkContent instead of SharePhotoContent. ShareLinkContent allows you to specify both a URL and photos to share.

Here's how you can modify your code to achieve this:

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()

In this code snippet, imageURL represents the URL of the image you want to share along with the link. You need to provide the URL of the image you want to share alongside the contentURL.

Make sure you have the appropriate permissions configured in your Facebook app settings to share links with photos. Additionally, ensure that the image you're trying to share is accessible and properly formatted for sharing on Facebook.

for multiple photos can you please try the below changes

// Assuming `sharePhotos` is an array of `UIImage` objects
let photoContent = SharePhotoContent()
photoContent.photos = sharePhotos.map { SharePhoto(image: $0, userGenerated: true) }

let linkContent = ShareLinkContent()
linkContent.contentURL = url
linkContent.hashtag = Hashtag("#Hapufood")

let content = ShareMediaContent()
content.media = [photoContent, linkContent]

// Display the share dialog
let dialog = ShareDialog(viewController: UIApplication.shared.keyWindow?.rootViewController, content: content, delegate: nil)
dialog.show()
3
  • Thanks for the answer, but i want to share a list of photos, not only one. Do you have any solution for this? Commented Feb 19 at 7:09
  • @túnguyễn, updated the changes can please try once. Commented Feb 19 at 7:39
  • Oke let me try it, thank you very much Commented Feb 19 at 10:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.