【问题标题】:Sharing text on Facebook programatically IOS is not possible now现在无法以编程方式在 Facebook 上共享文本 IOS
【发布时间】:2016-06-25 05:46:41
【问题描述】:

我无法在 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 分享无效

我该怎么办?

【问题讨论】:

  • 请注意,不允许预填充消息

标签: ios swift facebook sharing


【解决方案1】:

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

【讨论】:

  • 你的意思是我应该先做一个按钮和 IBOutlet 作为 _fbButton ,然后做上面的事情。
  • 您可以将调用 UIAlertController 的 UIButton 更改为帖子中的描述。
  • 我还没明白亲爱的
  • _fbButton.shareContent = fbContent
  • @M.AsimKhan _fbButton 是实例化 FBSDKShareButton 的变量。或者你的问题是什么?
【解决方案2】:

根据 Facebook 政策,不允许发布带有预填充文本的内容。看看这个https://developers.facebook.com/docs/apps/review/prefill

【讨论】:

    【解决方案3】:

    你可以分享文字。

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

    【讨论】:

    • 我们在 else 条件下做什么?我收到此错误SLComposeViewController isAvailableForServiceType com.apple.social.facebook returning 0
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多