Add UIImage directly to FBSDKShareLinkContent with Swift?

I have an FBSDK sharing function that works with the following code:

if (FBSDKAccessToken.currentAccessToken() != nil) {
        // User is already logged in, do work such as go to

        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) // 51 = 1/2 of height of descLabel, 30 = space below
        self.view.addSubview(button)
+4
source share
1

, FBSDKSharePhotoContent - , , Facebook, , .

https://developers.facebook.com/bugs/949486035103197/

, Facebook v31. v7 7 , FB , , .

+1

All Articles