【问题标题】:Facebook SDK for iOS: FBSDKShareDialog is not shown适用于 iOS 的 Facebook SDK:未显示 FBSDKShareDialog
【发布时间】:2015-10-22 20:54:16
【问题描述】:

我是 iOS 新手,我想分享一个使用 Facebook SDK for iOS 的链接。我的代码如下:

@IBAction func shareVoucherUsingFacebook(sender: UIButton) {
    print("Facebook")
    let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
    content.contentURL = NSURL(string: "www.google.com")
    content.contentTitle = "Content Title"
    content.contentDescription = "This is the description"

    let shareDialog: FBSDKShareDialog = FBSDKShareDialog()

    shareDialog.shareContent = content
    shareDialog.delegate = self
    shareDialog.fromViewController = self
    shareDialog.show()

}

我也实现了FBSDKSharingDelegate方法,但是当我按下这个按钮时我无法接收到共享对话框,并且方法func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!)正在执行,这意味着出了点问题,但我可以'想不通。

提前致谢。

【问题讨论】:

  • 您找到解决方案了吗?我现在遇到了同样的问题...

标签: ios swift swift2 facebook-sdk-4.0


【解决方案1】:

改变这一行

content.contentURL = NSURL(string: "www.google.com")

进入

content.contentURL = NSURL(string: "https:\\www.google.com")

和我一起工作

这是我使用的委托方法

func sharer(sharer: FBSDKSharing!, didCompleteWithResults results: [NSObject: AnyObject])
{
    print(results)
}

func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!)
{
    print("sharer NSError")
    print(error.description)
}

func sharerDidCancel(sharer: FBSDKSharing!)
{
    print("sharerDidCancel")
}

【讨论】:

  • Swift 无法将这些方法识别为委托的。没有找到将这些 ObjC 方法正确翻译成 Swift 的解决方案
【解决方案2】:

如果您在代码中使用NSURL(string:""),请记住将http:// 添加到您的contentURL

let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://www.google.com")
content.contentTitle = "Content Title"
content.contentDescription = "This is the description"

FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self)

【讨论】:

  • 谢谢,这对 Swift4 也非常有效
【解决方案3】:

实现委托方法对我有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    相关资源
    最近更新 更多