我无法在swift中以编程方式在Facebook上分享文字。 请看我的代码。 就是这样,
let facebookPostAction = UIAlertAction(title: "Share on Facebook", style: UIAlertActionStyle.Default)
{ (action) -> Void in
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
let facebookComposeVC = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookComposeVC.setInitialText("\(self.noteTextview.text)")
self.presentViewController(facebookComposeVC, animated: true, completion: nil)
}
else {
self.showAlertMessage("You are not connected to your Facebook account.")
}
}
最后这个功能在运行时告诉我
facebook分享无效
我该怎么办?
答案 0 :(得分:3)
Facebook已经改变了共享政策,因此您需要使用他们的SDK进行共享。 现在开发人员需要安装FBSDKShareKit.framework,以及带有上下文信息的简单添加按钮。
https://developers.facebook.com/docs/sharing/ios
简单地说,你需要通过从UIButton扩展的方式添加 FBSDKShareButton ,并将上下文数据设置为它:
_fbButton = FBSDKShareButton()
...
// setup visual part
// don't need to add target, facebook's sdk decides action
...
// set context data to shareContent button's property
let fbContent = FBSDKShareLinkContent()
fbContent.contentURL = value.contentURL
fbContent.contentTitle = value.contentTitle
fbContent.contentDescription = value.contentDescription
fbContent.imageURL = value.imageURL
_fbButton.shareContent = fbContent
全部,Facebook的共享面板将在此按钮内触摸后显示包含的数据。
答案 1 :(得分:3)
根据Facebook政策,不允许使用预先填写的文字进行发布。看看https://developers.facebook.com/docs/apps/review/prefill
答案 2 :(得分:1)
您可以分享文字。试试这个
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
let fbShare:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
fbShare.title="share"
self.presentViewController(fbShare, animated: true, completion: nil)
} else {
let alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}