我是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!)
方法,这意味着出现了问题,但我无法弄明白。
提前致谢。
改变这条线
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")
}
如果你在代码中使用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)
实现委托方法对我来说很有用