简体   繁体   English

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

[英]Facebook SDK for iOS: FBSDKShareDialog is not shown

I am a newbie in iOS, and I would like to share a link using the Facebook SDK for iOS. 我是iOS的新手,我想使用iOS版Facebook SDK共享链接。 My code's as follows: 我的代码如下:

@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()

}

I have also implemented the FBSDKSharingDelegate methods, but I am not able to receive the share dialog when I press this button, and the method func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!) is being executed, which means something is going wrong, but I can't figure it out. 我还实现了FBSDKSharingDelegate方法,但是当我按下此按钮时,我无法接收到共享对话框,并且正在执行方法func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!) ,这意味着有事情要发生了。错了,但我不知道。

Thanks in advance. 提前致谢。

changing this line 改变这条线

content.contentURL = NSURL(string: "www.google.com")

into

content.contentURL = NSURL(string: "https:\\www.google.com")

worked with me 和我一起工作

this is the delegate methods I used 这是我使用的委托方法

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

Just remember to add http:// to your contentURL if you are using NSURL(string:"") in your code. 如果您在代码中使用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)

实现委托方法对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM