现在无法通过编程 IOS 在 Facebook 上共享文本

Sharing text on Facebook programatically IOS is not possible now

我无法在 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 share is invalidated

我该怎么办?

Facebook改变了分享政策,所以你需要使用他们的SDK分享。 现在开发人员需要安装 FBSDKShareKit.framework,以及带有上下文信息的简单添加按钮。

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

简单的说,你需要添加FBSDKShareButton,顺便从UIButton扩展,并设置上下文数据:

_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 的共享面板将在触摸此按钮内部后显示包含的数据。

您可以分享文字。

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

根据 Facebook 政策,不允许使用 pre-filled 文字发帖。检查一下 https://developers.facebook.com/docs/apps/review/prefill