在Facebook上分享IOS 11 Swift

Sas*_*sha 5 share facebook ios swift ios11

在低于11的版本中,Facebook的ShareButton可以成功运行,但是在11版本中,此功能不起作用。您能提供什么建议?

if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook) {
        var vc: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
        vc.setInitialText("My text")
        self.present(vc, animated: true, completion: nil)
    }
Run Code Online (Sandbox Code Playgroud)

Jay*_*yas 6

您可以使用facebook sdk共享内容

步骤1:

安装吊舱:- pod 'FacebookShare'

第2步:

导入FBSDKShareKit

第三步:

func shareTextOnFaceBook() {
    let shareContent = ShareLinkContent()
    shareContent.contentURL = URL.init(string: "https://developers.facebook.com")! //your link
    shareContent.quote = "Text to be shared"
    ShareDialog(fromViewController: self, content: shareContent, delegate: self).show()
}

func sharer(_ sharer: Sharing, didCompleteWithResults results: [String : Any]) {
    if sharer.shareContent.pageID != nil {
        print("Share: Success")
    }
}
func sharer(_ sharer: Sharing, didFailWithError error: Error) {
    print("Share: Fail")
}
func sharerDidCancel(_ sharer: Sharing) {
    print("Share: Cancel")
}
Run Code Online (Sandbox Code Playgroud)

步骤4:必须在其中添加 Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>fbauth2</string>
</array>
Run Code Online (Sandbox Code Playgroud)