I have an FBSDK sharing function that works with the following code:
if (FBSDKAccessToken.currentAccessToken() != nil) {
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: self.url_string)
content.contentTitle = self.title_text
content.contentDescription = self.desc_text
content.imageURL = NSURL(string: "http://image.png")
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 30)
button.center = self.view.center
self.view.addSubview(button)
}
The problem is that I do not have imageURL, I have an image taken directly from the application's camera function, saved as a UIImage variable. How can I attach an image to this FBSDKShareLinkContent without an image posted on the Internet? I use FBSDKShareLinkContent because I also use the w / title and description link.
Edit, I'm trying to make FBSDKSharePhoto (as someone suggested) with this code that allows me to post a photo, but I canβt get the URL to link correctly, even if itβs content.contentURLdefined as it was before.
let photo : FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = self.scaledImage
photo.userGenerated = true
let content : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
content.contentURL = NSURL(string: self.url_string)
content.photos = [photo]
let button : FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 30)
button.center = CGPointMake(self.view.center.x, self.descLabel.center.y + 51 + 30)
self.view.addSubview(button)
source
share