适用于iOS的Facebook SDK:未显示FBSDKShareDialog
我是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") }
如果您在代码中使用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)