首页 > 解决方案 > iOS11 已弃用社交框架

问题描述

我正在制作一个示例 facebook 分享应用程序来使用分享按钮分享一些字符串值,但我很困惑,因为社交在 ios 11 中被破坏了

我现在应该使用什么代码,我已经为 swift 安装了 facebook sdk

我想要我已经在谷歌上搜索过的 siwft 语言的代码我发现不是对我的情况有用的代码

这是我在 onclikbutton 操作下使用的代码

@IBAction func shareButton(_ sender: Any) {


let alert = UIAlertController(title: "Share", message: "Poem Of the day", preferredStyle: .actionSheet)

    let actionOne = UIAlertAction(title: "Share on Facebook", style: .default) { (action) in
        print("Success")



    }

    alert.addAction(actionOne)
    self.present(alert, animated: true, completion: nil)

}

编辑:-找到了一种更好的方法来使用下面的代码在 facebook 上分享帖子

@IBAction func shareButton(_ sender: Any) {



    let content = FBSDKShareLinkContent()
    content.contentURL =  URL(string: "https://github.com/EndLess728")


    let dialog : FBSDKShareDialog = FBSDKShareDialog()
    dialog.fromViewController = self
    dialog.shareContent = content
    dialog.mode = FBSDKShareDialogMode.feedWeb
    dialog.show()

}

标签: swiftios11social-framework

解决方案


用于UIActivityViewController分享内容……</p>

@IBAction func share(_ sender: Any) {

    let sharingItems: [Any] = [URL(string: "https://github.com/EndLess728")]

    let activityController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)

    present(activityController, animated: true)
}

推荐阅读