适用于iOS的Facebook SDK:未显示FBSDKShareDialog

时间:2015-10-22 20:54:17

标签: ios swift swift2 facebook-sdk-4.0

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

@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!),这意味着出现了问题,但我无法弄清楚。

提前致谢。

3 个答案:

答案 0 :(得分:3)

更改此行

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

答案 1 :(得分:2)

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

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)

答案 2 :(得分:0)

实现委托方法对我来说很成功