Skip to main content
ShareLinkContent represents a URL you want to share to Facebook. You can attach a user-provided quote and a hashtag to the post.

Properties

PropertyTypeDescription
contentURLURL?The URL to share. The SDK checks it for App Links metadata.
quoteString?A quote displayed with custom styling on top of the link preview. Must come from the user — pre-filled quotes are against Facebook Platform Policy.
hashtagHashtag?A single hashtag attached to the share.
peopleIDs[String]IDs of friends to tag in the post (requires Taggable Friends permission).
placeIDString?The ID of a place to tag.
refString?A string appended to the referrer URL when someone follows the link from feed.
pageIDString?Maps the app to a page for Messenger attribution.
shareUUIDString?A read-only unique identifier generated automatically for tracking purposes.
1

Create the content object

Instantiate ShareLinkContent and set contentURL to the URL you want to share.
import FacebookShare

let content = ShareLinkContent()
content.contentURL = URL(string: "https://example.com/article")
2

Add a quote (optional)

The quote renders with highlighted styling above the link preview. It must originate from the user — do not pre-fill it.
content.quote = userEnteredQuote
3

Add a hashtag (optional)

Create a Hashtag and assign it. The string must start with # followed by one or more word characters.
content.hashtag = Hashtag("#SwiftDev")
4

Present the dialog

Pass the content to ShareDialog.
ShareDialog.show(viewController: self, content: content, delegate: self)

The Hashtag type

Hashtag is a simple wrapper around a string. You initialise it with the # character included:
let hashtag = Hashtag("#iOSDev")
print(hashtag.isValid)            // true
print(hashtag.stringRepresentation) // "#iOSDev"
A hashtag is valid when its stringRepresentation matches ^#\w+$ — a single # followed by one or more word characters. Invalid hashtags are silently dropped during sharing.
let bad = Hashtag("no hash sign")
print(bad.isValid) // false

Complete example

import FacebookShare
import UIKit

class ArticleViewController: UIViewController {

    func shareArticle(url: URL, userQuote: String?) {
        let content = ShareLinkContent()
        content.contentURL = url
        content.hashtag = Hashtag("#ReadMore")

        if let quote = userQuote {
            content.quote = quote
        }

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

extension ArticleViewController: SharingDelegate {

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

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

    func sharerDidCancel(_ sharer: Sharing) {
        print("Share cancelled")
    }
}
contentURL must be a network URL (not a file URL). The SDK validates this and throws if the URL is a local file path.

Build docs developers (and LLMs) love