繁体   English   中英

分享到 Facebook IOS 11 Swift

[英]Share on Facebook IOS 11 Swift

在低于 11 ShareButton 到 facebook 的版本中成功运行,但在 11 版本中此功能不起作用。 你有什么建议?

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

您可以使用 facebook sdk 来分享内容 Like

第 1 步:

安装 pod :- pod 'FacebookShare'

第 2 步:

导入 FBSDKShareKit

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

第 4 步:必须在Info.plist添加它

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

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

请参阅此处: https : //developer.apple.com/documentation/social/social_constants

您可以使用 FBSDKShareKit 来实现 facebook 上的分享功能。

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

现在,使用 FBSDKShareKit 在 facebook 中共享媒体更容易、更可靠。 您可以按照以下链接获取详细教程。

Facebook, Messenger - iOS Swift 中的照片、视频、链接共享。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM