I try add description and title for share link content . I am using pod 'FacebookShare' (because when i using FBSDKShareKit, description and title are deprecated)
https://i.sstatic.net/9p9lp.jpg
This my code with 'FacebookShare' :
do{
var myContent: LinkShareContent = LinkShareContent(url: NSURL(string:contentUrl!) as! URL )
myContent.description = "Some description"
myContent.title = "Hello"
let shareDialog = ShareDialog(content: myContent)
shareDialog.mode = .shareSheet
shareDialog.presentingViewController = self
shareDialog.failsOnInvalidData = true
shareDialog.completion = { result in
// Handle share results
}
try shareDialog.show()
} catch {
print("Error: \(error)")
}
But i can see description and title only when i using : shareDialog.mode = .native In all other cases( .shareSheet, .Web, .Browser, .FeedWeb, .FeedBrowser) they don't added. I am not want use .native mode because not everyone has native Facebook app. Is there any solution for my case?
****UPDATE:****
set up the proper meta tags on the site (which is i sharing url) itself for title, description and image values and for other variables.
You should update your myContent
and shareDialog
parts like this:
let myContent:FBSDKShareLinkContent = FBSDKShareLinkContent()
myContent.contentTitle = "Hello"
myContent.contentDescription = "Test message"
myContent.contentURL = (URL(string: "https://developers.facebook.com"))
let shareDialog = FBSDKShareDialog()
shareDialog.mode = .shareSheet
FBSDKShareDialog.show(from: self, with: myContent, delegate: nil)
You can also import and use Social
library for creating Facebook share box. And control your share results with Facebook share delegate functions. Like this way:
import FBSDKShareKit
import Social
class YourViewController: UIViewController, FBSDKSharingDelegate {
func facebookShareButtonClicked() {
let vc = SLComposeViewController(forServiceType:SLServiceTypeFacebook)
vc?.add(UIImage(named: "YourImageName"))
vc?.add(URL(string: "https://developers.facebook.com")) //Your custom URL
vc?.setInitialText("Your sample share message...")
self.present(vc!, animated: true, completion: nil)
}
//Facebook share delegate functions:
func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!) {
print("Success")
}
func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!) {
print("didFailWithError: ", error)
}
func sharerDidCancel(_ sharer: FBSDKSharing!) {
print("Sharer cancelled")
}
}
Note: Try it with your device. It doesn't work on simulator. And be sure that the Facebook App is installed your device.