Share Extension — What It Is, How It Works, and How to Develop an Extension

Author: IT Sectr Published: 2026-06-15 Reading time: 10 min

Share Extension is an iOS extension that adds your app to the system Share Sheet. Users can send content from Safari, Photos, Files, or any other app directly to yours — without copying and switching between windows. According to Apple (2024), apps with a Share Extension receive 35% more user content than apps without sharing capabilities. The extension handles text, images, video, URLs, and files through a unified NSExtensionItem interface.

Key Takeaways

  • Share Extension — an iOS extension for sending content to an app from other programs.
  • NSExtensionItem — a container for transferring data between the host app and the extension.
  • Info.plist — configuration of content types that the extension handles.
  • SLServiceTypes — mapping to social networks (Twitter, Facebook) for legacy mode.
  • App Groups — shared storage for transferring data between the extension and the app.

What Is a Share Extension

Share Extension is a type of iOS app extension that appears in the system Share Sheet when content is selected in any app. A user highlights text in Safari, taps "Share", and sees your app in the list of available actions. After selection, the content is passed to the extension for processing: saving, publishing, sending, or transforming.

Unlike Action Extension, Share Extension specializes in receiving content from external apps. Action Extension, on the other hand, sends data from your app outward. Share Extension is a user content entry point, a key element of user acquisition: users try your app through Share Extension without fully installing it. The App Store prohibits apps whose sole function is to display ads through Share Extension (App Store Review Guideline 4.2).

Why Share Extension Matters for Your App

Share Extension lowers the entry barrier: users send content to your app from a familiar context — browser, gallery, file manager. According to Branch (2024), apps with Share Extension show 28% higher 7-day retention. An additional effect is virality: each time a user sees your app in the Share Sheet, passive branding occurs without ad spend.

How a Share Extension Works

The Share Extension mechanism is based on content transfer via system NSExtensionItem containers. The host app (Safari, Photos) packages the selected content into an NSExtensionItem with a specified type (public.image, public.url, public.plain-text). The system passes this container to the extension, which extracts the data via extensionContext.inputItems.

Extension Lifecycle

Share Extension runs in a separate process with limited execution time — about 30 seconds for processing. The extension should not perform long synchronous operations. For uploading large files, use NSURLSession with a background configuration. SLComposeServiceViewController is the base class for Share Extension with content preview and a post button.

Data Types and Uniform Type Identifiers

iOS uses Uniform Type Identifiers (UTI) to determine the type of content being transferred. Main UTIs for Share Extension: public.image (photos, screenshots), public.url (links), public.plain-text (text), public.video (video files), and public.file-url (files). The extension registers supported UTIs in Info.plist via the NSExtensionActivationRule key.

Extension Architecture

Share Extension consists of three components: the Xcode target, SLComposeServiceViewController, and Info.plist configuration. Architecture determines which content types are handled, how the interface is displayed, and where data is saved.

ComponentPurposeFeatures
TargetExtension target in XcodeSeparate bundle with an identifier
ViewControllerInterface and processing logicSLComposeServiceViewController or custom
Info.plistActivation and UTI configurationNSExtensionActivationRule with predicates
App GroupsShared storage with the appUserDefaults suite for data transfer

NSExtensionActivationRule

The key configuration element of Share Extension is the activation rule. It determines under what conditions the extension appears in the Share Sheet. The rule is set in Info.plist as a dictionary with constraints: maximum number of images, minimum text length, mandatory URL presence. The standard rule activates the extension for any single content type.

objective-c
// Info.plist — NSExtensionActivationRule for Share Extension
<key>NSExtensionActivationRule</key>
<dict>
    <key>NSExtensionActivationSupportsImageWithMaxCount</key>
    <integer>5</integer>
    <key>NSExtensionActivationSupportsText</key>
    <true/>
    <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
    <integer>1</integer>
</dict>

Creating a Share Extension

Let us look at a practical example of creating a Share Extension in Swift for a bookmarking app. The extension receives a URL from Safari, displays a preview interface, and saves the link in App Group. SLComposeServiceViewController provides a ready-made UI with a text field and a Post button.

swift
import Social
import MobileCoreServices

class ShareViewController: SLComposeServiceViewController {

    override func isContentValid() -> Bool {
        return !(contentText?.isEmpty() ?? true)
    }

    override func didSelectPost() {
        guard let item = extensionContext?.inputItems.first as? NSExtensionItem
        else { return }

        for attachment in item.attachments ?? [] {
            attachment.loadItem(forTypeIdentifier: kUTTypeURL as String) {
                [weak self] (item, error) in
                if let url = item as? URL {
                    BookmarkService().save(url, title: self?.contentText)
                }
                self?.extensionContext?.completeRequest(
                    returningItems: [], completionHandler: nil)
            }
        }
    }
}

After sending content, the extension finishes by calling completeRequest — this is a mandatory step; without it, the system will not release the extension process. Important: Share Extension runs in a limited environment with restricted network and file system access — use background sessions for content uploads.

Processing Content Types

Share Extension must correctly handle different types of input data: text, images, video, URLs, and files. Each type uses its own UTI and extraction method. Universal handling — iterating through attachment.attachments with hasItemConformingToTypeIdentifier checks.

Image Handling

Images are passed as public.image with the ability to retrieve them via UIImage or Data. For large images, use jpegData(compressionQuality:) before saving. Share Extension should not modify the original image without explicit user permission. It is recommended to save the original in App Group and create a preview for display in the interface.

URL and Text Handling

Safari and other browsers pass URLs as public.url and selected text as public.plain-text. A single NSExtensionItem can contain both types simultaneously — the page URL and the selected text on it. Share Extension should check all attachments and extract relevant data. Combined scenario: save the URL as a bookmark and the text as a note attached to it.

App Groups and Data Transfer

Share Extension and the main app run in different processes and do not share file system access. Data exchange uses the App Groups mechanism: a shared container with a group.* identifier. After saving data in App Group, the extension notifies the app via CFNotificationCenter or Darwin Notify.

Setting Up App Groups

App Groups are enabled in the target's Capabilities: select "App Groups" and add an identifier (e.g., group.com.example.myapp). Both targets — the main app and the extension — must have access to the same group. UserDefaults suite allows reading and writing data to the shared storage with minimal overhead.

swift
// Saving data to App Group from Share Extension
let sharedDefaults = UserDefaults(suiteName: "group.com.example.myapp")
let bookmark: [String: Any] = [
    "url": url.absoluteString,
    "title": contentText ?? "",
    "date": Date().timeIntervalSince1970
]
sharedDefaults?.set(bookmark, forKey: "bookmark_\(Date().timeIntervalSince1970)")
sharedDefaults?.synchronize()

Frequently Asked Questions

How is Share Extension different from Action Extension?

Share Extension receives content from other apps into yours. Action Extension, on the other hand, performs an action on content within the host app — translating text, modifying an image. Share Extension is receiving, Action Extension is transformation.

Which UTIs should I specify in Info.plist?

It depends on the type of content your app handles. For bookmarks — public.url. For a photo editor — public.image. For notes — public.plain-text. For multiple types, use NSExtensionActivationRule with a combination of AND/OR predicates.

Why doesn't Share Extension appear in the Share Sheet?

A common cause is an incorrect NSExtensionActivationRule or UTI mismatch. Check in Info.plist: the activation rule must match the tested content type. Also ensure the extension is enabled in Settings → your app → Siri & Search. Xcode clean build often resolves the issue.

How much time does Share Extension have for processing?

The system allocates about 30 seconds for execution. After that, iOS forcefully terminates the extension process. For long-running operations, use a background NSURLSession and handle the result on the next app launch.

Can I display custom UI in Share Extension?

Yes, instead of SLComposeServiceViewController you can use a regular UIViewController. In this case, you have full control over the interface. However, you need to implement the send and cancel buttons yourself. Custom UI is recommended for non-standard content processing scenarios.

Summary

  • Share Extension — an iOS extension that adds your app to the system Share Sheet.
  • Content is transferred via NSExtensionItem with Uniform Type Identifiers.
  • Activation configuration is set in Info.plist via NSExtensionActivationRule.
  • SLComposeServiceViewController — base UI with preview and posting.
  • App Groups — a mechanism for data exchange between the extension and the app.
  • Share Extension runs in a limited environment (30 sec, restricted access).
  • Apps with a Share Extension receive 35% more user content.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also