# Share a Photo from Your iOS App



You can share a photo by using the `FacebookShareKit` framework. This topic shows you how to write the code to share a photo in your app.

To share a photo, you will create the objects for the photo to share and then invoke a share method to share the photo. The two objects for the photo are a [`SharePhoto`](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKShareKit/classes/fbsdksharephoto.html) object for the photo and a [`SharePhotoContent`](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKShareKit/classes/fbsdksharephotocontent.html) object as the model for the photo content.

After you create the objects, you can share the photo in one of the following ways:

* [Message Dialog](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKShareKit/classes/fbsdkmessagedialog.html) - a dialog to send content through Messenger.

* [Send Button](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKShareKit/classes.html) - sends the photo through Messenger.

* [Share Dialog](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKShareKit/classes/fbsdksharedialog.html) - a dialog to share content.

* [Share Button](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKShareKit/classes.html) - sends the photo by showing the Share Dialog.

This topic shows how to use the Share Dialog.

**Note:** Due to a limitation with Xcode, you can only test sharing a photo on an iOS device and not in the xCode simulator. Run this this code on a device.

## Before You Start

You will need to integrate the `FacebookShareKit` framework from the Facebook SDK for iOS. [Learn more](https://developers.facebook.com/documentation/ios/getting-started).

Add the following `import` statement:

```c
import FBSDKShareKit
```

## Step 1: Set the [`SharePhoto`](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKShareKit/classes/fbsdksharephoto.html) object to the image you want to share

The `SharePhoto` is the photo that you want to share. Add this code to set the `SharePhoto` object to the photo.

```c
let photo = SharePhoto(image: image, userGenerated: true)
```

## Step 2: Set the [`SharePhotoContent`](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKShareKit/classes/fbsdksharephotocontent.html) object to the `SharePhoto` object

The `SharePhotoContent` is the model of the photo content you want to share. Add this code for the `SharePhotoContent` object.

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

## Step 3: Show the Share Dialog

Add this code to show the Share Dialog.

```c
let dialog = ShareDialog(
    fromViewController: self,
    content: content,
    delegate: self
)

// Recommended to validate before trying to display the dialog
do {
    try dialog.validate()
} catch {
    // Handle error
}

dialog.show()
```