Search code examples
iosswiftswift2facebook-sdk-4.0

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. 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.


Solution

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