社交框架在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()
}
解决方案
使用UIActivityViewController
共享Content…
@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)
}
相关文章