Facebook SDK for iOS: FBSDKShareDialog is not shown

百般思念 提交于 2019-12-24 00:36:54

问题


I am a newbie in iOS, and I would like to share a link using the Facebook SDK for iOS. 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.

Thanks in advance.


回答1:


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



回答2:


Just remember to add http:// to your contentURL if you are using NSURL(string:"") in your code.

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)



回答3:


implementing the delegate methods did the trick for me



来源:https://stackoverflow.com/questions/33290566/facebook-sdk-for-ios-fbsdksharedialog-is-not-shown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!