iOS 的 Facebook SDK:未显示 FBSDKShareDialog

Facebook SDK for iOS: FBSDKShareDialog is not shown

我是 iOS 的新手,我想分享 link 使用 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!)方法,说明有问题错了,但我想不通。

提前致谢。

更改此行

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

如果您在代码中使用 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)

实现委托方法对我有用