在 Facebook 上分享 IOS 11 Swift

Share on Facebook IOS 11 Swift

Share Button to facebook 11以下的版本可以正常使用,但是11版本这个功能不可用。你有什么建议?

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

所有社交常量(facebook、twitter、LinkedIn 等)已在 iOS 11 上弃用。

看这里: https://developer.apple.com/documentation/social/social_constants

facebook分享功能可以使用FBSDKShareKit

https://developers.facebook.com/docs/sharing/ios/

您可以使用facebook sdk分享内容 喜欢

Step 1:

安装 pod :- pod 'FacebookShare'

Step 2:

导入 FBSDKShareKit

Step 3:

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")
}

Step 4: Must add this in Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>fbauth2</string>
</array>

现在使用 FBSDKShareKit 在 facebook 中共享媒体更容易、更可靠。详细教程可参考下方link

Facebook, Messenger - Photo, Video, Link sharing in iOS Swift.