问题
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