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

问题描述 投票:2回答:3

我是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
3个回答
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")
}

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)

0
投票

实现委托方法对我来说很有用

© www.soinside.com 2019 - 2024. All rights reserved.