# Share Extension

> Share extension with NSExtensionActivationRule filtering, SLComposeServiceViewController handling, App Group data sharing, and shared content processing for URLs, text, and images. Use when adding share sheet integration to an iOS app.

- Skill: `abdullah4ai/share-extension` (Agent Skill)
- Install (CLI): `npx skillmds@latest add abdullah4ai/share-extension`
- Raw SKILL.md: https://api.skillmd.com/api/skills/abdullah4ai/share-extension/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: abdullah4ai (https://skillmd.com/u/abdullah4ai)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/abdullah4ai/share-extension

---

# Share Extension

## Overview

The share extension receives content (URLs, text, images) from other apps via the system share sheet. It runs as a separate process with limited memory and no direct access to the main app's data unless App Groups are configured.

## Setup

Requires a separate extension target configured as `kind: "share"` in the plan extensions array.

## Principal View Controller

Implement `SLComposeServiceViewController` to handle shared content:

```swift
import Social
import UniformTypeIdentifiers

class ShareViewController: SLComposeServiceViewController {
    override func isContentValid() -> Bool {
        return contentText.count > 0
    }

    override func didSelectPost() {
        guard let item = extensionContext?.inputItems.first as? NSExtensionItem,
              let provider = item.attachments?.first else {
            extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
            return
        }

        if provider.hasItemConformingToTypeIdentifier("public.url") {
            provider.loadItem(forTypeIdentifier: "public.url") { [weak self] url, _ in
                // Process the shared URL
                self?.extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
            }
        }
    }

    override func configurationItems() -> [Any]! {
        return []  // Return SLComposeSheetConfigurationItem array for extra UI rows
    }
}
```

## Info.plist Configuration

Set these keys in the extension target's Info.plist (via XcodeGen):

```
NSExtensionPrincipalClass: $(PRODUCT_MODULE_NAME).ShareViewController
NSExtensionActivationRule:
  NSExtensionActivationSupportsWebURLWithMaxCount: 1
  NSExtensionActivationSupportsText: true
```

## Data Sharing via App Groups

Use the App Group entitlement to share data between the main app and the extension. Both targets must belong to the same App Group to access shared `UserDefaults` or a shared container directory.

