facebook / facebook/facebook-ios-sdk

"Photo Content Sharing" isn't working to Facebook share

Open
#2,500 3 comments 0 reactions 0 assignees View on GitHub
bug needs-triage
Dominant language
Swift
Stars
8.1k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

### Checklist before submitting a bug report

- [x] I've updated to the latest released version of the SDK
- [X] I've searched for existing [GitHub issues](https://github.com/facebook/facebook-ios-sdk/issues)
- [X] I've looked for existing answers on [Stack Overflow](https://facebook.stackoverflow.com), the [Facebook Developer Community Forum](https://developers.facebook.com/community/) and the [Facebook Developers Group](https://www.facebook.com/groups/fbdevelopers)
- [X] I've read the [Code of Conduct](https://github.com/facebook/facebook-ios-sdk/blob/main/CODE_OF_CONDUCT.md)
- [X] This issue is not security related and can safely be disclosed publicly on GitHub

### Xcode version

15.1

### Facebook iOS SDK version

17.0.0

### Dependency Manager

CocoaPods

### SDK Framework

Share

### Goals

Share photo to Facebook is also can be success in development environment.

### Expected results

share photo to facebook and can find it in facebook

### Actual results

After I clicked Share to Facebook, it jumped to the Facebook post page and previewed the sent content and image, but after clicking the post button, it came back to my app and didn't receive any SharingDelegate callback(didCompleteWithResults, didFailWithError or sharerDidCancel)

And then I went to my Facebook profile to look for it, I didn't find the content I just posted.

I confirmed that if I click on cancel posting I will get the sharerDidCancel callback.

Anything else, if I share content that is not an image but a URL, it is successful and will have the didCompleteWithResults callback.

### Steps to reproduce

It's happen in a development environment every time, but if it's downloaded from the appstore, there is no problem

### Code samples & details

```swift
extension ShareFacebookService {
private func sharePhotoContent(_ viewModel: SocialShareFacebookViewModel) {
guard let vc = UIApplication.shared.itKeyWindow?.visibleViewController else {
self.completionHandlerBlock?(false, "viewController nil")
return
}

if let images = viewModel.images, images.count > 0 {

let photoContent = SharePhotoContent.init()
var photos: [SharePhoto] = []

for image in images {
let photo = SharePhoto.init(image: image, isUserGenerated: true)
photos.append(photo)
}

photoContent.photos = photos

if let tag = viewModel.hashtag {
photoContent.hashtag = Hashtag.init("#\(tag)")
}

if let contentURL = viewModel.contentUrl,
let url = URL.init(string: contentURL) {
photoContent.contentURL = url
}
let dialog = ShareDialog(viewController: vc, content: photoContent, delegate: self)
dialog.mode = SocialShareFacebookService.isInstalled() ? .native : .automatic
dialog.show()
}else {
self.completionHandlerBlock?(false, "image count is 0")
}
}
private func shareLinkContent(_ viewModel: SocialShareFacebookViewModel) {
guard let vc = UIApplication.shared.itKeyWindow?.visibleViewController else {
self.completionHandlerBlock?(false, "viewController nil")
return
}
let linkContent = ShareLinkContent.init()
if let tag = viewModel.hashtag {
linkContent.hashtag = Hashtag.init("#\(tag)")
}

if let contentURL = viewModel.contentUrl,
let url = URL.init(string: contentURL) {
linkContent.contentURL = url
}

if let quote = viewModel.quote {
linkContent.quote = quote
}
let dialog = ShareDialog(viewController: vc, content: linkContent, delegate: self)
dialog.mode = SocialShareFacebookService.isInstalled() ? .native : .automatic
dialog.show()
}
}

extension ShareFacebookService: SharingDelegate {
func sharer(_ sharer: Sharing, didCompleteWithResults results: [String : Any]) {
completionHandlerBlock?(true, nil)
}

func sharer(_ sharer: Sharing, didFailWithError error: Error) {
completionHandlerBlock?(false, error.localizedDescription)
}

func sharerDidCancel(_ sharer: Sharing) {
completionHandlerBlock?(false, nil)
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.