ShareDialog is the main entry point for sharing content on Facebook. It wraps the content you want to share, chooses the best presentation mode available, and notifies your code of the outcome through a delegate.
Creating and presenting a dialog
The simplest way to share is the one-line class methodshow(viewController:content:delegate:). It creates a dialog, calls show() on it, and returns the dialog instance.
If you do not supply a
viewController, the SDK attempts to find the topmost view controller automatically. Supplying one explicitly is recommended.Dialog modes
Setdialog.mode to control how the dialog is presented. The default is .automatic.
| Mode | Description |
|---|---|
.automatic | Chooses the best available mode at runtime. Start here. |
.native | Opens the share sheet inside the Facebook app. The Facebook app must be installed. |
.shareSheet | Uses the iOS integrated share sheet. The Facebook app must be installed. |
.browser | Opens the share dialog in Safari. |
.web | Opens the dialog in a WKWebView inside your app. Deprecated — prefer .automatic. |
.feedBrowser | Opens the feed dialog in Safari. Deprecated — prefer .browser. |
.feedWeb | Opens the feed dialog in a WKWebView. Deprecated — prefer .automatic. |
Checking availability before sharing
Before callingshow(), you can check whether the dialog can be presented with the canShow property. This is useful when you want to hide or disable a share button conditionally.
Implementing SharingDelegate
Conform to SharingDelegate to receive callbacks when sharing completes, fails, or is cancelled by the user.
When the user is not signed into your app, the SDK may not be able to distinguish between a completion and a cancellation. Your delegate should handle both gracefully.
Handling data errors
By default,shouldFailOnDataError is false. This means the dialog still appears even when some parts of the content are invalid (for example, an invalid placeID). Set it to true if you want the share to fail fast instead:
Validating content without showing the dialog
Callvalidate() to check the content is valid for the current mode before presenting the dialog. This method throws if something is wrong.