首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于iOS的Facebook :未显示FBSDKShareDialog

用于iOS的Facebook :未显示FBSDKShareDialog
EN

Stack Overflow用户
提问于 2015-10-22 20:54:16
回答 3查看 4.2K关注 0票数 3

我是iOS的新手,我想通过分享一个链接。我的代码如下:

代码语言:javascript
复制
@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!)方法正在执行,这意味着出了问题,但我找不出答案。

提前谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-07-14 08:12:18

改变这条线

代码语言:javascript
复制
content.contentURL = NSURL(string: "www.google.com")

转到

代码语言:javascript
复制
content.contentURL = NSURL(string: "https:\\www.google.com")

和我一起工作

这是我使用的委托方法。

代码语言:javascript
复制
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")
}
票数 3
EN

Stack Overflow用户

发布于 2016-07-14 08:18:45

如果在代码中使用http://,请记住将contentURL添加到NSURL(string:"")

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2019-04-02 15:05:21

实现委托方法对我很有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33290566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档