App extensions

From rshankras/claude-code-apple-skills · View interactive version

App extensions is an AI agent skill from the GitHub repository rshankras/claude-code-apple-skills. Generates app extension infrastructure for Share Extensions, Action Extensions, Keyboard Extensions, and Safari Web Extensions with data sharing via App Groups. Use when user wants to add a share extension, action extension, keyboard extension, Safari web extension, or any app extension type.

How to use this skill

Skill file

App Extensions Generator

Generate production app extension infrastructure -- Share Extensions for receiving content from other apps, Action Extensions for manipulating content in-place, Keyboard Extensions for custom input, and Safari Web Extensions for browser integration. Includes App Group data sharing between the host app and extensions.

When This Skill Activates

Use this skill when the user:

Pre-Generation Checks

1. Project Context Detection

2. Existing Extension Detection

Search for existing extension targets:

Glob: **/*Extension*/*.swift, **/*Extension*/Info.plist
Grep: "NSExtensionPointIdentifier" or "NSExtensionPrincipalClass"

If existing extensions found:

3. App Groups Detection

Check for existing App Groups setup:

Glob: **/*.entitlements
Grep: "com.apple.security.application-groups"

If App Groups exist, reuse the existing group identifier.

Configuration Questions

Ask user via AskUserQuestion:

  1. What type of extension?
  1. What content types does it handle?
  1. Does the extension need to share data with the main app?

Generation Process

Step 1: Read Templates

Read templates.md for production Swift code.

Step 2: Create Extension Files

Based on extension type selected:

Share Extension:

  1. ShareViewController.swift -- Main share extension view controller with content handling
  2. Info.plist -- Extension configuration with activation rules

Action Extension:

  1. ActionViewController.swift -- Action extension with content manipulation
  2. Info.plist -- Extension configuration

Keyboard Extension:

  1. KeyboardViewController.swift -- Custom keyboard with UIInputViewController
  2. Info.plist -- Keyboard extension configuration

Safari Web Extension:

  1. SafariWebExtensionHandler.swift -- Native message handler
  2. manifest.json -- Web extension manifest
  3. content.js -- Content script template

Step 3: Create Shared Infrastructure

If data sharing selected:

  1. SharedDataManager.swift -- App Group data sharing helper

Step 4: Determine File Location

Extensions are separate targets:

Output Format

After generation, provide:

Files Created

Share Extension:

ShareExtension/
├── ShareViewController.swift  # Main share extension view controller
└── Info.plist                 # Extension activation rules & config

Action Extension:

ActionExtension/
├── ActionViewController.swift # Content manipulation controller
└── Info.plist                 # Extension activation rules & config

Keyboard Extension:

KeyboardExtension/
├── KeyboardViewController.swift # UIInputViewController subclass
└── Info.plist                   # Keyboard extension config

Safari Web Extension:

SafariWebExtension/
├── SafariWebExtensionHandler.swift # Native message handler
└── Resources/
    ├── manifest.json               # Web extension manifest
    ├── content.js                  # Content script
    └── popup.html                  # Popup UI (optional)

Shared (if data sharing enabled):

Shared/
└── SharedDataManager.swift    # App Group data sharing

Integration Steps

1. Add Extension Target in Xcode:

2. Configure App Groups (if data sharing):

3. Share code between targets:

Extension Content Handling

Accept shared URLs:

if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
    provider.loadItem(forTypeIdentifier: UTType.url.identifier) { item, error in
        guard let url = item as? URL else { return }
        // Process URL
    }
}

Accept shared images:

if provider.hasItemConformingToTypeIdentifier(UTType.image.identifier) {
    provider.loadItem(forTypeIdentifier: UTType.image.identifier) { item, error in
        if let imageURL = item as? URL {
            let imageData = try? Data(contentsOf: imageURL)
            // Process image data
        }
    }
}

Share data to main app via App Groups:

let shared = SharedDataManager.shared
shared.saveSharedContent(url.absoluteString, forKey: "lastSharedURL")

Testing

Share Extension:

  1. Build and run the extension scheme
  2. Select a host app (Safari, Photos, etc.)
  3. Share content and verify your extension appears
  4. Test with different content types

Action Extension:

  1. Build and run the extension scheme
  2. Open content in a supported app
  3. Tap the share/action button and select your action

Keyboard Extension:

  1. Build and run the keyboard extension scheme
  2. Go to Settings > General > Keyboard > Keyboards > Add New Keyboard
  3. Select your keyboard
  4. Open any text field and switch to your keyboard

Safari Web Extension:

  1. Build and run the app (which contains the extension)
  2. Go to Safari > Settings > Extensions
  3. Enable your extension
  4. Navigate to a web page and verify behavior

Extension Lifecycle and Limits

Memory Limits

Execution Limits

Extension Termination

The system can terminate extensions at any time for resource reclamation. Save state frequently and handle interruption gracefully.

Gotchas

completeRequest Must Be Called

The extension host waits for extensionContext?.completeRequest(returningItems:). If you never call it, the share sheet hangs and the user is stuck. Always call it in both success and error paths.

Keyboard Extensions Need Open Access for Network

By default keyboard extensions have no network access. The user must explicitly grant "Allow Full Access" in Settings. Without it, URLSession calls fail silently. Design your keyboard to work without network and enhance when access is granted.

App Groups Require Matching Identifiers

The App Group identifier must be identical in both the main app and extension entitlements. A typo means UserDefaults(suiteName:) returns a different (empty) container.

Safari Web Extension Content Scripts Run in Isolated World

Content scripts cannot directly access the page's JavaScript variables. Use window.postMessage or the browser messaging API to communicate between content scripts and the page.

Extension Bundle Identifier Convention

Extension bundle identifiers must be prefixed with the main app bundle identifier:

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.