UIActivityViewController for Facebook not Showing Default Text

后端 未结 6 1335
心在旅途
心在旅途 2020-12-02 13:04

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

6条回答
  •  [愿得一人]
    2020-12-02 13:51

    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
    

提交回复
热议问题