Facebook SDK Share Image with Text

Before using the Facebook SDK, which we used to share through the UIActivityViewController, since Facebook does not allow us to pre-populate user sharing information, our solution was to use information about how a custom image image is UIPasteboard.general.string . Therefore, the application will switch to the messenger, and the user can insert it. This worked fine until we started using the Facebook SDK.

Now it seems that UIPasteboard.general.string is reset when it opens the messenger, and we can no longer get a description of the image copied to the clipboard.

Here's how I share with the messenger:

 let sharePhoto = FBSDKSharePhoto() sharePhoto.image = image let content = FBSDKSharePhotoContent() content.photos = [sharePhoto] FBSDKMessageDialog.show(with: content, delegate: delegate) 
+5
source share
3 answers

Yes, I also fit into this state after updating FB lib. As for me - I found out that the link to the web link is an image, as shown below. As a result, you don’t need to ask the user to insert something. You can do it yourself and insert it into the title or description.

 let content = LinkShareContent(url: url, title: title, description: description, quote: nil, imageURL: imageURL) let dialog = ShareDialog(content: content) dialog.presentingViewController = parentVC dialog.mode = .automatic dialog.completion = { result in ... } try? dialog.show() 
+2
source

Facebook does not support the user interface for both image and text. If you want to share the image and text together, you can create a user story from your application settings and share it as open graphics. Here is the documentation .

0
source

a

It worked for me.

  if FBSDKAccessToken.current().hasGranted("publish_actions") { let photoToShare = FBSDKSharePhoto() photoToShare.caption = "put some text in here" photoToShare.image = UIimage(named: "imagename") let content = FBSDKSharePhotoContent() content.photos = [photoToShare] FBSDKShareAPI.share(with: content, delegate: self) } else { print("require publish_actions permissions") let login: FBSDKLoginManager = FBSDKLoginManager() login.logIn(withPublishPermissions: ["publish_actions"], from: self) { (result, error) in if (error != nil) { print(error!) } else if (result?.isCancelled)! { print("Canceled") } else if (result?.grantedPermissions.contains("publish_actions"))! { print("permissions granted") } } } 
0
source

Source: https://habr.com/ru/post/1275957/


All Articles