I am using a UIActivityViewController which provides some default text and a link. With all social mediums (sms, email, twitter) the default text and URL are shown. Howeve
Based on @Kashifs solution. Here is a version in Swift 4.2, Xcode 10 and FacebookSDK 4.4.
import FBSDKShareKit
extension YourViewController: UIActivityItemSource{
//MARK: - ActionSheet
func showShareSheet(){
let shareStr = "Text you want to share"
let activItems = [self,shareStr, #imageLiteral(resourceName: "YourImageName")] as [Any]
let shareSheet = UIActivityViewController(activityItems: activItems, applicationActivities: nil)
self.shareSheet = shareSheet
self.present(shareSheet, animated: true, completion: nil)
}
//MARK: - FacebookPost
func postToFacebook() {
let quote = "Text you want to share"
if let URL = URL(string: "https://yourURL"){
let content : LinkShareContent = LinkShareContent(url: URL, quote: quote)
let dialog = ShareDialog(content: content)
dialog.mode = .shareSheet
dialog.presentingViewController = self
do{
try dialog.show()
}catch{
print("\(error)")
}
}
}
//MARK: - UIActivityItemSource Protocol
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any?{
if activityType == UIActivity.ActivityType.postToFacebook{
self.shareSheet?.dismiss(animated: true, completion: {
self.postToFacebook()
})
}
return nil
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return ""
}
}//endReferral/Invite-Share