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

hujrc8aj  于 2022-11-06  发布在  Swift
关注(0)|答案(3)|浏览(179)

我是一个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!)正在执行,这意味着有什么地方出错了,但是我不能弄清楚。
先谢谢你。

rta7y2nd

rta7y2nd1#

更改此行

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

wdebmtf22#

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

ibps3vxo3#

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

相关问题