Skip to main content

Overview

SharePhotoContent holds an array of SharePhoto objects to share as a Facebook photo post. You can share between 1 and 10 photos at once. Module: FacebookShare
Declared in: SharePhotoContent.swift
Objective-C name: FBSDKSharePhotoContent
Conforms to: SharingContent, SharingValidatable

Initializer

SharePhotoContent uses the default initializer. Create an instance and configure its properties directly:
let content = SharePhotoContent()
content.photos = [SharePhoto(image: myImage, isUserGenerated: true)]

Properties

photos
[SharePhoto]
The array of photos to share. Must contain between 1 and 10 SharePhoto objects. Validation fails if the array is empty or exceeds 10 items.
contentURL
URL?
An optional URL associated with the photo content. Checked for App Links meta tags.
hashtag
Hashtag?
An optional hashtag to include with the share.
peopleIDs
[String]
User IDs to tag in the post. Defaults to an empty array.
placeID
String?
The ID of a Facebook Place to tag with this content.
pageID
String?
For Messenger shares, this page ID maps the app to a page and attaches attribution.
shareUUID
String?
A unique identifier automatically generated for this share instance.

SharePhoto

SharePhoto represents a single photo. Only one source may be active at a time: image, imageURL, or photoAsset. Objective-C name: FBSDKSharePhoto

Initializers

init(image:isUserGenerated:)

public convenience init(image: UIImage, isUserGenerated: Bool)
image
UIImage
A UIImage that is already in memory.
isUserGenerated
Bool
true if the photo was created by the user, false if generated by the application. Platform policy (section 2.3) requires user-generated captions.

init(imageURL:isUserGenerated:)

public convenience init(imageURL: URL, isUserGenerated: Bool)
imageURL
URL
A file URL pointing to a photo on disk. Use this instead of a remote URL; to share a web image, download it first and use init(image:isUserGenerated:).
isUserGenerated
Bool
Whether the photo was created by the user.

init(photoAsset:isUserGenerated:)

public convenience init(photoAsset: PHAsset, isUserGenerated: Bool)
photoAsset
PHAsset
A PHAsset from the Photos library. Must refer to an image (not a video).
isUserGenerated
Bool
Whether the photo was created by the user.

Properties

image
UIImage?
A UIImage in memory. Setting this clears imageURL and photoAsset.
imageURL
URL?
A URL pointing to the photo. Setting this clears image and photoAsset.
photoAsset
PHAsset?
A PHAsset from the Photos library. Setting this clears image and imageURL.
isUserGenerated
Bool
Indicates whether the photo was created by the user.
caption
String?
An optional user-generated caption for the photo. Pre-filled captions are not permitted by Platform Policies.

Usage example

import FacebookShare

// Share a photo from memory
let photo = SharePhoto(image: capturedImage, isUserGenerated: true)
photo.caption = nil  // Do not pre-fill captions

let content = SharePhotoContent()
content.photos = [photo]

ShareDialog.show(
    viewController: self,
    content: content,
    delegate: self
)

// Share from the Photos library
let asset: PHAsset = selectedAsset
let assetPhoto = SharePhoto(photoAsset: asset, isUserGenerated: true)
let assetContent = SharePhotoContent()
assetContent.photos = [assetPhoto]

Build docs developers (and LLMs) love