我是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!)
,这意味着出现了问题,但我无法弄清楚。
提前致谢。
答案 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)
实现委托方法对我来说很成功