Cannot share a photo to Messanger iOS Facebook SDK - ios

I'm trying to share a photo to Messanger but it fails without returning any error.
But if I create a link instead of photo it works successfully.
photo.image = image
photo.isUserGenerated = true
let content = FBSDKSharePhotoContent()
content.photos = [photo]
FBSDKMessageDialog.show(with: content, delegate: nil)

Related

Swift iOS Facebook SDK: How to share an animated GIF?

I have a document's directory path of a gif I'd like to post to Facebook, but unfortunately when I use this process, it posts a static image instead of it being animated. I know it's animated because I can save the same image to my camera roll and see that it animates. Is there anyway of posting an animated version of this GIF?
let image = UIImage(contentsOfFile: path) // document directory path
let sharePhoto = FBSDKSharePhoto()
sharePhoto.image = image
let content = FBSDKSharePhotoContent()
content.photos = [sharePhoto]
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = content
shareDialog.mode = .native
shareDialog.show()
This is not as issue with your image due to Facebook natively not support gif image directly uploaded on it.
You can share gif image link on Facebook and it will show there gif image. Like as commonly peoples are using giphy, tenor website and share gif image link from this website. So gif image display via this type of website.
I hope this will help you.

share photo with standard text - Facebook iOS SDK 4.x

I need to post a picture on the user's wall with a standard text. Can you do this with the FBSDK 4.x?
let photoshare = FBSDKSharePhoto(image: recortarImagem(), userGenerated: true)
let content = FBSDKSharePhotoContent()
content.photos = [photoshare]
let dialog = FBSDKShareDialog()
dialog.delegate = self
dialog.shareContent = content
dialog.fromViewController = self
dialog.mode = FBSDKShareDialogMode.ShareSheet
dialog.show()
As pointed out in the comments, this would violate the Platform Policy of Facebook (see 2.3, pre-filling at https://developers.facebook.com/policy/#control).
This being said, FBSDKSharePhoto has a field, caption that you can put a user-generated message in.

Image quality degrades with FBSDKshareDialog and FBSDKsharephoto

I have used the following code to capture a screenshot before using the image to post to Facebook:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(frame.size.width,frame.size.height), false, 0)
self.view?.drawViewHierarchyInRect(CGRectMake(-frame.origin.x, -frame.origin.y, view.bounds.size.width, view.bounds.size.height), afterScreenUpdates: false)
let screenShot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return screenShot
In the first instance I used the Social Framework and SLComposeViewController adding the screenshot with addImage. The image on the dialog box and ultimate post were perfect but this method does not allow you to choose your friends.
I then decided to use use FBSDKDialog as follows:
let photo : FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = screenShot
photo.userGenerated = false
photo.caption = contentDescription
let photoContent : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
photoContent.photos = [photo]
photoContent.contentURL = NSURL(string: self.contentURL)
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = self
shareDialog.shareContent = photoContent
shareDialog.delegate = self
if !shareDialog.canShow() {
shareDialog.mode = FBSDKShareDialogMode.Native
} else {
shareDialog.mode = FBSDKShareDialogMode.FeedBrowser
}
shareDialog.show()
The code works perfectly but the image quality on the share dialog box is extremely poor. Yet when I do make the post the image quality on the timeline is perfect.
I have tried to compress the image but nothing seems to make any difference.
Can anyone suggest what I am doing wrong?
Thank you.
You're not doing anything wrong. This is probably a way Facebook optimizes sharing.

Add UIImage directly into FBSDKShareLinkContent with Swift?

I have the FBSDK sharing function working 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 don't have an imageURL, I have an image taken directly from the app's camera function stored as a UIImage variable. How can I attach an image to this FBSDKShareLinkContent without the image being hosted online? I'm using FBSDKShareLinkContent because I'm also sharing a link w/ title & description.
Edit, I'm trying FBSDKSharePhoto (as someone suggested) with this code, which lets me post the photo, but I can't get the URL to link properly even though content.contentURL is defined 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)
Appears that the FBSDKSharePhotoContent is the way to go, but there is currently a bug that Facebook is aware of, which is causing the image & link to not work together.
https://developers.facebook.com/bugs/949486035103197/
They say this should be updated in the next Facebook app update v31. v30 was updated May 7 and FB releases updates every two weeks, so I'll check back in a week and confirm that the functionality is fixed.

ios sharekit 2.0 not showing image preview when sharing image

I'm using Sharekit2.0 to share images to facebook and twitter.
Here is the code used for sharing the image in facebook.
SHKItem *sharerItem = [SHKItem image:image title:#""];
SHKTwitter *sharer = [[SHKTwitter alloc] init];
[sharer setItem:sharerItem];
[sharer share];
But this not showing any preview of the image when sharing (like twitter is showing). just a text view to enter title for image.
My question would be: is it possible to show to image preview when sharing to facebook ?
Thanks
Try:
SHKItem * sharerItem = [SHKItem image:image title:#"P"];
[SHKTwitter shareItem:sharerItem];

Resources