Skip to main content

Overview

ShareDialog is the main entry point for sharing content on Facebook. It supports multiple presentation modes—native app, iOS share sheet, browser, and web—and chooses the best available mode automatically when you use .automatic. Module: FacebookShare
Declared in: ShareDialog.swift
Objective-C name: FBSDKShareDialog

Supported content types

Content typeClass
LinksShareLinkContent
PhotosSharePhotoContent
VideosShareVideoContent
Camera effectsShareCameraEffectContent
Mixed mediaShareMediaContent

Initializer

init(viewController:content:delegate:)

@objc(initWithViewController:content:delegate:)
public init(
    viewController: UIViewController?,
    content: SharingContent?,
    delegate: SharingDelegate?
)
viewController
UIViewController?
The view controller from which to present the dialog. Pass nil to use the topmost view controller.
content
SharingContent?
The content to share. Must be one of the supported content types listed above.
delegate
SharingDelegate?
A weak delegate that receives share completion, cancellation, and failure callbacks.

Static factory methods

ShareDialog.dialog(viewController:content:delegate:)

Creates but does not show a ShareDialog.
@objc(dialogWithViewController:withContent:delegate:)
public class func dialog(
    viewController: UIViewController?,
    content: SharingContent?,
    delegate: SharingDelegate?
) -> ShareDialog

ShareDialog.show(viewController:content:delegate:)

Creates and immediately shows a ShareDialog.
@discardableResult
@objc(showFromViewController:withContent:delegate:)
public class func show(
    viewController: UIViewController?,
    content: SharingContent?,
    delegate: SharingDelegate?
) -> ShareDialog

Properties

fromViewController
UIViewController?
The view controller from which the dialog is presented. Weak reference.
mode
ShareDialog.Mode
Controls how the dialog is presented. Defaults to .automatic. See ShareDialog.Mode.
shareContent
SharingContent?
The content to be shared. You can update this before calling show().
delegate
SharingDelegate?
The object receiving share lifecycle events. Weak reference.
shouldFailOnDataError
Bool
When true, the dialog fails if it detects invalid data in the share content. When false, the dialog is still shown but the misconfigured data is omitted. Defaults to false.
canShow
Bool
true if the dialog can be shown given the current mode, content, and device capabilities. Check this before calling show() if you want to avoid a failed attempt.

Methods

show()

Presents the share dialog.
@discardableResult
public func show() -> Bool
return value
Bool
true if the dialog was displayed successfully, false if validation failed.

ShareDialog.Mode enum

CaseDescription
.automaticSelects the best available mode automatically (default).
.nativePresents the dialog inside the main Facebook app. Requires the Facebook app to be installed.
.shareSheetUses the iOS integrated share sheet (SLComposeViewController). Requires the Facebook app to be installed.
.browserOpens the share dialog in Safari.
.web(Deprecated) Opens in a WKWebView inside your app.
.feedBrowser(Deprecated) Opens the feed dialog in Safari.
.feedWeb(Deprecated) Opens the feed dialog in a WKWebView.

SharingDelegate protocol

Implement this protocol to receive the result of a share attempt. Objective-C name: FBSDKSharingDelegate

sharer(_:didCompleteWithResults:)

Called when sharing completes without error or cancellation.
func sharer(_ sharer: Sharing, didCompleteWithResults results: [String: Any])
sharer
Sharing
The sharer that completed.
results
[String: Any]
A dictionary of results from the share dialog. May be empty.

sharer(_:didFailWithError:)

Called when the sharer encounters an error.
func sharer(_ sharer: Sharing, didFailWithError error: Error)

sharerDidCancel(_:)

Called when the user dismisses the share dialog without sharing.
func sharerDidCancel(_ sharer: Sharing)

Usage example

import FacebookShare

class ShareViewController: UIViewController, SharingDelegate {

    func shareLink() {
        let content = ShareLinkContent()
        content.contentURL = URL(string: "https://developers.facebook.com/")

        let dialog = ShareDialog(
            viewController: self,
            content: content,
            delegate: self
        )
        dialog.mode = .automatic
        dialog.show()
    }

    // MARK: - SharingDelegate

    func sharer(_ sharer: Sharing, didCompleteWithResults results: [String: Any]) {
        print("Share completed:", results)
    }

    func sharer(_ sharer: Sharing, didFailWithError error: Error) {
        print("Share failed:", error)
    }

    func sharerDidCancel(_ sharer: Sharing) {
        print("Share cancelled")
    }
}

Build docs developers (and LLMs) love