App clip

From gustavscirulis/snapgrid · View interactive version

App clip is an AI agent skill from the GitHub repository gustavscirulis/snapgrid. Generates App Clip targets with invocation URL handling, lightweight experiences, and full app upgrade prompts. Use when user wants NFC/QR/Safari banner invocation, instant app experiences, or App Clip Card setup.

How to use this skill

Skill file

App Clip Generator

Generate production App Clip infrastructure — a lightweight version of your app invoked from NFC tags, QR codes, Safari banners, or Messages. Includes App Clip target setup, invocation URL handling, experience routing, location confirmation, and full app upgrade flow.

When This Skill Activates

Use this skill when the user:

Pre-Generation Checks

1. Project Context Detection

2. Conflict Detection

Search for existing App Clip targets:

Glob: **/*AppClip*/*.swift, **/*Clip*/*.swift
Grep: "NSUserActivityTypeBrowsingWeb" or "AppClipExperience" or "SKOverlay"

If existing App Clip target found:

3. Project Structure

Identify where the main app target lives and where to place the App Clip target alongside it.

Configuration Questions

Ask user via AskUserQuestion:

  1. Invocation method?
  1. Primary experience?
  1. Include location confirmation?
  1. Include full app upgrade prompt?

Generation Process

Step 1: Read Templates

Read templates.md for production Swift code.

Read patterns.md for constraints, testing, and best practices.

Step 2: Create Core Files

Generate these files:

  1. AppClipApp.swift — @main App struct handling invocation via .onContinueUserActivity
  2. InvocationHandler.swift — Parses invocation URL, extracts parameters, validates against registered experiences
  3. AppClipExperience.swift — Protocol and concrete experience implementations

Step 3: Create Location Files (if selected)

  1. LocationConfirmationView.swift — CLLocationManager-based location verification for physical invocations

Step 4: Create Upgrade Files (if selected)

  1. FullAppUpgradeView.swift — SKOverlay-based banner prompting full app download
  2. SharedDataManager.swift — App Group data sharing between App Clip and full app

Step 5: Determine File Location

Check project structure:

Output Format

After generation, provide:

Files Created

AppClip/
├── AppClipApp.swift              # @main entry point with invocation handling
├── InvocationHandler.swift       # URL parsing and parameter extraction
├── AppClipExperience.swift       # Experience protocol and implementations
├── LocationConfirmationView.swift # Location verification (optional)
├── FullAppUpgradeView.swift      # SKOverlay upgrade prompt (optional)
└── SharedDataManager.swift       # App Group data sharing (optional)

Xcode Target Setup Instructions

  1. Add App Clip Target:
  1. Configure Associated Domains:
  1. Set Up App Group:
  1. Apple-App-Site-Association (AASA) file:

Integration

Handle invocation in the App Clip:

@main
struct MyAppClip: App {
    @State private var handler = InvocationHandler()

    var body: some Scene {
        WindowGroup {
            ContentView(experience: handler.currentExperience)
                .onContinueUserActivity(
                    NSUserActivityTypeBrowsingWeb
                ) { activity in
                    handler.handle(activity)
                }
        }
    }
}

Route to the correct experience:

struct ContentView: View {
    let experience: (any AppClipExperience)?

    var body: some View {
        if let experience {
            AnyView(experience.makeView())
        } else {
            DefaultExperienceView()
        }
    }
}

Share data with the full app:

// In App Clip — save order before user upgrades
SharedDataManager.shared.save(order, forKey: "pendingOrder")

// In Full App — restore after install
if let order: Order = SharedDataManager.shared.load(forKey: "pendingOrder") {
    showOrder(order)
}

Prompt full app download:

FullAppUpgradeView(
    appStoreID: "123456789",
    benefits: [
        "Order history and favorites",
        "Loyalty rewards program",
        "Push notification for order updates"
    ]
)

Testing

@Test
func invocationHandlerParsesProductURL() {
    let handler = InvocationHandler()
    let url = URL(string: "https://example.com/clip/product/abc123")!

    let experience = handler.parseURL(url)

    #expect(experience != nil)
    #expect(experience?.experienceType == .previewContent)
    #expect(experience?.parameters["productID"] == "abc123")
}

@Test
func invocationHandlerRejectsInvalidURL() {
    let handler = InvocationHandler()
    let url = URL(string: "https://other-domain.com/something")!

    let experience = handler.parseURL(url)

    #expect(experience == nil)
}

@Test
func sharedDataManagerRoundTrips() {
    let manager = SharedDataManager(suiteName: "group.test")
    let order = Order(id: "order-1", items: ["Latte", "Muffin"])

    manager.save(order, forKey: "testOrder")
    let loaded: Order? = manager.load(forKey: "testOrder")

    #expect(loaded?.id == "order-1")
    #expect(loaded?.items.count == 2)
}

Common Patterns

Handle Invocation URL

Every App Clip starts from a URL. Parse it to determine what experience to show:

// URL: https://example.com/clip/order?location=store-42
// -> Route to OrderExperience with locationID = "store-42"

Present Experience Immediately

Users expect instant value. Show the relevant experience within 1-2 seconds, no sign-in required.

Prompt Full App Install

After the user completes the primary task, show an SKOverlay banner with clear benefits of the full app.

Gotchas

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.