axiom-app-shortcuts-ref

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

App Shortcuts Reference

App Shortcuts 参考文档

Overview

概述

Comprehensive guide to App Shortcuts framework for making your app's actions instantly available in Siri, Spotlight, Action Button, Control Center, and other system experiences. App Shortcuts are pre-configured App Intents that work immediately after app install—no user setup required.
Key distinction App Intents are the actions; App Shortcuts are the pre-configured "surface" that makes those actions instantly discoverable system-wide.

本指南全面介绍App Shortcuts框架,帮助你让应用的操作在Siri、Spotlight、操作按钮、控制中心及其他系统体验中即时可用。App Shortcuts是预配置的App Intents,安装应用后即可立即使用——无需用户进行设置。
关键区别:App Intents是具体操作;App Shortcuts是预配置的“载体”,让这些操作能在全系统范围内即时被发现。

When to Use This Skill

何时使用本技能

Use this skill when:
  • Implementing AppShortcutsProvider for your app
  • Adding suggested phrases for Siri invocation
  • Configuring instant Spotlight availability
  • Creating parameterized shortcuts (skip Siri clarification)
  • Using NegativeAppShortcutPhrase to prevent false positives (iOS 17+)
  • Promoting shortcuts with SiriTipView
  • Updating shortcuts dynamically with updateAppShortcutParameters()
  • Debugging shortcuts not appearing in Shortcuts app or Spotlight
  • Choosing between App Intents and App Shortcuts
Do NOT use this skill for:
  • General App Intents implementation (use app-intents-ref)
  • Core Spotlight indexing (use core-spotlight-ref)
  • Overall discoverability strategy (use app-discoverability)

在以下场景使用本技能:
  • 为应用实现AppShortcutsProvider
  • 添加供Siri调用的建议短语
  • 配置Spotlight即时访问功能
  • 创建参数化快捷方式(跳过Siri确认步骤)
  • 使用NegativeAppShortcutPhrase避免误触发(iOS 17+)
  • 通过SiriTipView推广快捷方式
  • 使用updateAppShortcutParameters()动态更新快捷方式
  • 调试未在快捷指令应用或Spotlight中显示的快捷方式
  • 选择使用App Intents还是App Shortcuts
请勿在以下场景使用本技能:
  • 通用App Intents实现(使用app-intents-ref)
  • Core Spotlight索引(使用core-spotlight-ref)
  • 整体可发现性策略(使用app-discoverability)

Related Skills

相关技能

  • app-intents-ref — Complete App Intents implementation reference
  • app-discoverability — Strategic guide for making apps discoverable
  • core-spotlight-ref — Core Spotlight and NSUserActivity integration

  • app-intents-ref — 完整的App Intents实现参考
  • app-discoverability — 应用可发现性策略指南
  • core-spotlight-ref — Core Spotlight与NSUserActivity集成

App Shortcuts vs App Intents

App Shortcuts vs App Intents

AspectApp IntentApp Shortcut
DiscoveryMust be found in Shortcuts appInstantly available after install
ConfigurationUser configures in ShortcutsPre-configured by developer
Siri activationRequires custom phrase setupWorks immediately with provided phrases
SpotlightRequires donation or IndexedEntityAppears automatically
Action buttonNot directly accessibleCan be assigned immediately
Setup timeMinutes per userZero
When to use App Shortcuts Every app should provide App Shortcuts for core functionality. They dramatically improve discoverability with zero user effort.

维度App IntentApp Shortcut
可发现性需在快捷指令应用中查找安装应用后即时可用
配置方式用户在快捷指令应用中配置由开发者预配置
Siri激活需要用户设置自定义短语使用提供的短语即可立即生效
Spotlight支持需要捐赠或IndexedEntity自动显示
操作按钮支持无法直接访问可立即分配
设置时间每位用户需花费数分钟零设置时间
何时使用App Shortcuts:每个应用都应为核心功能提供App Shortcuts。它们无需用户付出任何努力,就能大幅提升应用的可发现性。

Core Concepts

核心概念

AppShortcutsProvider Protocol

AppShortcutsProvider 协议

Required conformance Your app must have exactly one type conforming to
AppShortcutsProvider
.
swift
struct MyAppShortcuts: AppShortcutsProvider {
    // Required: Define your shortcuts
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] { get }

    // Optional: Branding color
    static var shortcutTileColor: ShortcutTileColor { get }

    // Optional: Dynamic updates
    static func updateAppShortcutParameters()

    // Optional: Negative phrases (iOS 17+)
    static var negativePhrases: [NegativeAppShortcutPhrase] { get }
}
Platform support iOS 16+, iPadOS 16+, macOS 13+, tvOS 16+, watchOS 9+

必须实现:你的应用必须有且仅有一个类型遵循
AppShortcutsProvider
协议。
swift
struct MyAppShortcuts: AppShortcutsProvider {
    // 必填:定义你的快捷方式
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] { get }

    // 可选:品牌颜色
    static var shortcutTileColor: ShortcutTileColor { get }

    // 可选:动态更新
    static func updateAppShortcutParameters()

    // 可选:否定短语(iOS 17+)
    static var negativePhrases: [NegativeAppShortcutPhrase] { get }
}
平台支持:iOS 16+, iPadOS 16+, macOS 13+, tvOS 16+, watchOS 9+

AppShortcut Structure

AppShortcut 结构体

Associates an
AppIntent
with spoken phrases and metadata.
swift
AppShortcut(
    intent: StartMeditationIntent(),
    phrases: [
        "Start meditation in \(.applicationName)",
        "Begin mindfulness with \(.applicationName)"
    ],
    shortTitle: "Meditate",
    systemImageName: "figure.mind.and.body"
)
Components:
  • intent
    — The App Intent to execute
  • phrases
    — Spoken/typed phrases for Siri/Spotlight
  • shortTitle
    — Short label for Shortcuts app tiles
  • systemImageName
    — SF Symbol for visual representation

AppIntent
与语音短语和元数据关联起来。
swift
AppShortcut(
    intent: StartMeditationIntent(),
    phrases: [
        "Start meditation in \(.applicationName)",
        "Begin mindfulness with \(.applicationName)"
    ],
    shortTitle: "Meditate",
    systemImageName: "figure.mind.and.body"
)
组成部分
  • intent
    — 要执行的App Intent
  • phrases
    — 供Siri/Spotlight使用的语音/输入短语
  • shortTitle
    — 快捷指令应用中磁贴的短标题
  • systemImageName
    — 用于视觉展示的SF Symbol

AppShortcutPhrase (Suggested Phrases)

AppShortcutPhrase(建议短语)

String interpolation Phrases use
\(.applicationName)
to dynamically include your app's name.
swift
phrases: [
    "Start meditation in \(.applicationName)",
    "Meditate with \(.applicationName)"
]
User sees in Siri/Spotlight:
  • "Start meditation in Calm"
  • "Meditate with Calm"
Why this matters The system uses these exact phrases to trigger your intent via Siri and show suggestions in Spotlight.

字符串插值:短语使用
\(.applicationName)
来动态插入你的应用名称。
swift
phrases: [
    "Start meditation in \(.applicationName)",
    "Meditate with \(.applicationName)"
]
用户在Siri/Spotlight中看到的内容
  • "Start meditation in Calm"
  • "Meditate with Calm"
重要性:系统会使用这些精确的短语来通过Siri触发你的意图,并在Spotlight中显示建议。

@AppShortcutsBuilder

@AppShortcutsBuilder

Result builder for defining shortcuts array.
swift
@AppShortcutsBuilder
static var appShortcuts: [AppShortcut] {
    AppShortcut(intent: OrderIntent(), /* ... */)
    AppShortcut(intent: ReorderIntent(), /* ... */)

    if UserDefaults.standard.bool(forKey: "premiumUser") {
        AppShortcut(intent: CustomizeIntent(), /* ... */)
    }
}
Result builder features:
  • Conditional shortcuts (if/else)
  • Loop-generated shortcuts (for-in)
  • Inline array construction

用于定义快捷方式数组的结果构建器。
swift
@AppShortcutsBuilder
static var appShortcuts: [AppShortcut] {
    AppShortcut(intent: OrderIntent(), /* ... */)
    AppShortcut(intent: ReorderIntent(), /* ... */)

    if UserDefaults.standard.bool(forKey: "premiumUser") {
        AppShortcut(intent: CustomizeIntent(), /* ... */)
    }
}
结果构建器特性
  • 条件快捷方式(if/else)
  • 循环生成快捷方式(for-in)
  • 内联数组构造

Phrase Template Patterns

短语模板模式

Basic Phrases (No Parameters)

基础短语(无参数)

swift
AppShortcut(
    intent: StartWorkoutIntent(),
    phrases: [
        "Start workout in \(.applicationName)",
        "Begin exercise with \(.applicationName)",
        "Work out in \(.applicationName)"
    ],
    shortTitle: "Start Workout",
    systemImageName: "figure.run"
)
Benefits:
  • Simple, discoverable
  • Works for all users
  • No parameter ambiguity
Use when Intent has no required parameters or parameters have defaults.

swift
AppShortcut(
    intent: StartWorkoutIntent(),
    phrases: [
        "Start workout in \(.applicationName)",
        "Begin exercise with \(.applicationName)",
        "Work out in \(.applicationName)"
    ],
    shortTitle: "Start Workout",
    systemImageName: "figure.run"
)
优势
  • 简单、易发现
  • 适用于所有用户
  • 无参数歧义
适用场景:意图没有必填参数,或参数有默认值时。

Parameterized Phrases (Skip Clarification)

参数化短语(跳过确认步骤)

Pre-configure intents with specific parameter values to skip Siri's clarification step.
swift
// Intent with parameters
struct StartMeditationIntent: AppIntent {
    static var title: LocalizedStringResource = "Start Meditation"

    @Parameter(title: "Type")
    var meditationType: MeditationType?

    @Parameter(title: "Duration")
    var duration: Int?
}

// Shortcuts with different parameter combinations
@AppShortcutsBuilder
static var appShortcuts: [AppShortcut] {
    // Generic version (will ask for parameters)
    AppShortcut(
        intent: StartMeditationIntent(),
        phrases: ["Start meditation in \(.applicationName)"],
        shortTitle: "Meditate",
        systemImageName: "figure.mind.and.body"
    )

    // Specific versions (skip parameter step)
    AppShortcut(
        intent: StartMeditationIntent(
            meditationType: .mindfulness,
            duration: 10
        ),
        phrases: [
            "Start quick mindfulness in \(.applicationName)",
            "10 minute mindfulness in \(.applicationName)"
        ],
        shortTitle: "Quick Mindfulness",
        systemImageName: "brain.head.profile"
    )

    AppShortcut(
        intent: StartMeditationIntent(
            meditationType: .sleep,
            duration: 20
        ),
        phrases: [
            "Start sleep meditation in \(.applicationName)"
        ],
        shortTitle: "Sleep Meditation",
        systemImageName: "moon.stars.fill"
    )
}
Benefits:
  • One-phrase completion (no follow-up questions)
  • Better user experience for common use cases
  • Spotlight shows specific shortcuts
Trade-off More shortcuts = more visual clutter in Shortcuts app. Balance common cases (3-5 shortcuts) vs flexibility (generic shortcut with parameters).

预配置带有特定参数值的意图,跳过Siri的确认步骤。
swift
// 带参数的意图
struct StartMeditationIntent: AppIntent {
    static var title: LocalizedStringResource = "Start Meditation"

    @Parameter(title: "Type")
    var meditationType: MeditationType?

    @Parameter(title: "Duration")
    var duration: Int?
}

// 带有不同参数组合的快捷方式
@AppShortcutsBuilder
static var appShortcuts: [AppShortcut] {
    // 通用版本(会询问参数)
    AppShortcut(
        intent: StartMeditationIntent(),
        phrases: ["Start meditation in \(.applicationName)"],
        shortTitle: "Meditate",
        systemImageName: "figure.mind.and.body"
    )

    // 特定版本(跳过参数步骤)
    AppShortcut(
        intent: StartMeditationIntent(
            meditationType: .mindfulness,
            duration: 10
        ),
        phrases: [
            "Start quick mindfulness in \(.applicationName)",
            "10 minute mindfulness in \(.applicationName)"
        ],
        shortTitle: "Quick Mindfulness",
        systemImageName: "brain.head.profile"
    )

    AppShortcut(
        intent: StartMeditationIntent(
            meditationType: .sleep,
            duration: 20
        ),
        phrases: [
            "Start sleep meditation in \(.applicationName)"
        ],
        shortTitle: "Sleep Meditation",
        systemImageName: "moon.stars.fill"
    )
}
优势
  • 一句话完成操作(无需后续提问)
  • 为常见使用场景提供更好的用户体验
  • Spotlight会显示特定快捷方式
权衡:快捷方式越多,快捷指令应用中的视觉杂乱度越高。平衡常见场景(3-5个快捷方式)与灵活性(带参数的通用快捷方式)。

NegativeAppShortcutPhrase (iOS 17+)

NegativeAppShortcutPhrase(iOS 17+)

Train the system to NOT invoke your app for certain phrases.
swift
struct MeditationAppShortcuts: AppShortcutsProvider {
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        AppShortcut(
            intent: StartMeditationIntent(),
            phrases: ["Start meditation in \(.applicationName)"],
            shortTitle: "Meditate",
            systemImageName: "figure.mind.and.body"
        )
    }

    // Prevent false positives
    static var negativePhrases: [NegativeAppShortcutPhrase] {
        NegativeAppShortcutPhrases {
            "Stop meditation"
            "Cancel meditation"
            "End session"
        }
    }
}
When to use:
  • Phrases that sound similar to your shortcuts but mean the opposite
  • Common phrases users might say that shouldn't trigger your app
  • Disambiguation when multiple apps have similar capabilities
Platform iOS 17.0+, iPadOS 17.0+, macOS 14.0+, tvOS 17.0+, watchOS 10.0+

训练系统不要在某些短语下调用你的应用。
swift
struct MeditationAppShortcuts: AppShortcutsProvider {
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        AppShortcut(
            intent: StartMeditationIntent(),
            phrases: ["Start meditation in \(.applicationName)"],
            shortTitle: "Meditate",
            systemImageName: "figure.mind.and.body"
        )
    }

    // 防止误触发
    static var negativePhrases: [NegativeAppShortcutPhrase] {
        NegativeAppShortcutPhrases {
            "Stop meditation"
            "Cancel meditation"
            "End session"
        }
    }
}
适用场景
  • 与你的快捷方式听起来相似但含义相反的短语
  • 用户可能会说但不应触发应用的常见短语
  • 多个应用有相似功能时的消歧义
平台支持:iOS 17.0+, iPadOS 17.0+, macOS 14.0+, tvOS 17.0+, watchOS 10.0+

Discovery UI Components

可发现性UI组件

SiriTipView — Promote Shortcuts In-App

SiriTipView — 在应用内推广快捷方式

Display the spoken phrase for a shortcut directly in your app's UI.
swift
import AppIntents
import SwiftUI

struct OrderConfirmationView: View {
    @State private var showSiriTip = true

    var body: some View {
        VStack {
            Text("Order confirmed!")

            // Show Siri tip after successful order
            SiriTipView(intent: ReorderIntent(), isVisible: $showSiriTip)
                .siriTipViewStyle(.dark)
        }
    }
}
Requirements:
  • Intent must be used in an AppShortcut (otherwise shows empty view)
  • isVisible binding controls display state
Styles:
  • .automatic
    — Adapts to environment
  • .light
    — Light background
  • .dark
    — Dark background
Best practice Show after users complete actions, suggesting easier ways next time.

在应用UI中直接显示快捷方式的语音短语。
swift
import AppIntents
import SwiftUI

struct OrderConfirmationView: View {
    @State private var showSiriTip = true

    var body: some View {
        VStack {
            Text("Order confirmed!")

            // 下单成功后显示Siri提示
            SiriTipView(intent: ReorderIntent(), isVisible: $showSiriTip)
                .siriTipViewStyle(.dark)
        }
    }
}
要求
  • 意图必须在AppShortcut中使用(否则会显示空视图)
  • isVisible绑定控制显示状态
样式
  • .automatic
    — 适配环境
  • .light
    — 浅色背景
  • .dark
    — 深色背景
最佳实践:在用户完成操作后显示,提示用户下次使用更简便的方式。

ShortcutsLink — Link to Shortcuts App

ShortcutsLink — 链接到快捷指令应用

Opens your app's page in the Shortcuts app, listing all available shortcuts.
swift
import AppIntents
import SwiftUI

struct SettingsView: View {
    var body: some View {
        List {
            Section("Siri & Shortcuts") {
                ShortcutsLink()
                // Displays "Shortcuts" with standard link styling
            }
        }
    }
}
When to use:
  • Settings screen
  • Help/Support section
  • Onboarding flow
Benefits Single tap takes users to see all your app's shortcuts, with suggested phrases visible.

打开快捷指令应用中你的应用页面,列出所有可用的快捷方式。
swift
import AppIntents
import SwiftUI

struct SettingsView: View {
    var body: some View {
        List {
            Section("Siri & Shortcuts") {
                ShortcutsLink()
                // 显示“快捷方式”及标准链接样式
            }
        }
    }
}
适用场景
  • 设置页面
  • 帮助/支持板块
  • 引导流程
优势:一键即可让用户查看应用的所有快捷方式,并能看到建议短语。

ShortcutTileColor — Branding

ShortcutTileColor — 品牌化

Set the color for your shortcuts in the Shortcuts app.
swift
struct CoffeeAppShortcuts: AppShortcutsProvider {
    static var shortcutTileColor: ShortcutTileColor = .tangerine

    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        // ...
    }
}
Available colors:
ColorUse Case
.blue
Default, professional
.tangerine
Energy, food/beverage
.purple
Creative, meditation
.teal
Health, wellness
.red
Urgent, important
.pink
Lifestyle, social
.navy
Business, finance
.yellow
Productivity, notes
.lime
Fitness, outdoor
Full list:
.blue
,
.grape
,
.grayBlue
,
.grayBrown
,
.grayGreen
,
.lightBlue
,
.lime
,
.navy
,
.orange
,
.pink
,
.purple
,
.red
,
.tangerine
,
.teal
,
.yellow
Choose color that matches your app icon or brand identity.

设置快捷指令应用中你的快捷方式的磁贴颜色。
swift
struct CoffeeAppShortcuts: AppShortcutsProvider {
    static var shortcutTileColor: ShortcutTileColor = .tangerine

    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        // ...
    }
}
可用颜色
颜色适用场景
.blue
默认,专业风格
.tangerine
活力感,餐饮类应用
.purple
创意类,冥想类应用
.teal
健康类,养生类应用
.red
紧急类,重要操作
.pink
生活方式类,社交类应用
.navy
商务类,金融类应用
.yellow
生产力类,笔记类应用
.lime
健身类,户外类应用
完整列表:
.blue
,
.grape
,
.grayBlue
,
.grayBrown
,
.grayGreen
,
.lightBlue
,
.lime
,
.navy
,
.orange
,
.pink
,
.purple
,
.red
,
.tangerine
,
.teal
,
.yellow
颜色选择:匹配应用图标或品牌标识的颜色。

Dynamic Updates

动态更新

updateAppShortcutParameters()

updateAppShortcutParameters()

Call when parameter options change to refresh stored shortcuts.
swift
struct MeditationAppShortcuts: AppShortcutsProvider {
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        // Shortcuts can reference dynamic data
        for session in MeditationData.favoriteSessions {
            AppShortcut(
                intent: StartSessionIntent(session: session),
                phrases: ["Start \(session.name) in \(.applicationName)"],
                shortTitle: session.name,
                systemImageName: session.iconName
            )
        }
    }

    static func updateAppShortcutParameters() {
        // Called automatically when needed
        // Override only if you need custom behavior
    }
}

// In your app, when data changes
extension MeditationData {
    func markAsFavorite(_ session: Session) {
        favoriteSessions.append(session)

        // Update App Shortcuts to reflect new data
        MeditationAppShortcuts.updateAppShortcutParameters()
    }
}
When to call:
  • User adds/removes favorites
  • Available options change
  • App data structure updates
Automatic invocation The system calls this periodically, but you can force updates when you know data changed.

当参数选项变化时调用,刷新已存储的快捷方式。
swift
struct MeditationAppShortcuts: AppShortcutsProvider {
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        // 快捷方式可以引用动态数据
        for session in MeditationData.favoriteSessions {
            AppShortcut(
                intent: StartSessionIntent(session: session),
                phrases: ["Start \(session.name) in \(.applicationName)"],
                shortTitle: session.name,
                systemImageName: session.iconName
            )
        }
    }

    static func updateAppShortcutParameters() {
        // 系统会在需要时自动调用
        // 仅当需要自定义行为时才重写
    }
}

// 在应用中,当数据变化时
extension MeditationData {
    func markAsFavorite(_ session: Session) {
        favoriteSessions.append(session)

        // 更新App Shortcuts以反映新数据
        MeditationAppShortcuts.updateAppShortcutParameters()
    }
}
调用时机
  • 用户添加/移除收藏内容
  • 可用选项发生变化
  • 应用数据结构更新
自动调用:系统会定期调用此方法,但当你明确知道数据发生变化时,可以主动触发更新。

Complete Implementation Example

完整实现示例

Step 1: Define App Intents

步骤1:定义App Intents

swift
import AppIntents

struct OrderCoffeeIntent: AppIntent {
    static var title: LocalizedStringResource = "Order Coffee"
    static var description = IntentDescription("Orders coffee for pickup")

    @Parameter(title: "Coffee Type")
    var coffeeType: CoffeeType

    @Parameter(title: "Size")
    var size: CoffeeSize

    @Parameter(title: "Customizations")
    var customizations: String?

    static var parameterSummary: some ParameterSummary {
        Summary("Order \(\.$size) \(\.$coffeeType)") {
            \.$customizations
        }
    }

    func perform() async throws -> some IntentResult {
        let order = try await CoffeeService.shared.order(
            type: coffeeType,
            size: size,
            customizations: customizations
        )

        return .result(
            value: order,
            dialog: "Your \(size) \(coffeeType) is ordered for pickup"
        )
    }
}

struct ReorderLastIntent: AppIntent {
    static var title: LocalizedStringResource = "Reorder Last Coffee"
    static var description = IntentDescription("Reorders your most recent coffee")
    static var openAppWhenRun: Bool = false

    func perform() async throws -> some IntentResult {
        guard let lastOrder = try await CoffeeService.shared.lastOrder() else {
            throw CoffeeError.noRecentOrders
        }

        try await CoffeeService.shared.reorder(lastOrder)

        return .result(
            dialog: "Reordering your \(lastOrder.coffeeName)"
        )
    }
}

enum CoffeeType: String, AppEnum {
    case latte, cappuccino, americano, espresso

    static var typeDisplayRepresentation: TypeDisplayRepresentation = "Coffee"
    static var caseDisplayRepresentations: [CoffeeType: DisplayRepresentation] = [
        .latte: "Latte",
        .cappuccino: "Cappuccino",
        .americano: "Americano",
        .espresso: "Espresso"
    ]
}

enum CoffeeSize: String, AppEnum {
    case small, medium, large

    static var typeDisplayRepresentation: TypeDisplayRepresentation = "Size"
    static var caseDisplayRepresentations: [CoffeeSize: DisplayRepresentation] = [
        .small: "Small",
        .medium: "Medium",
        .large: "Large"
    ]
}

swift
import AppIntents

struct OrderCoffeeIntent: AppIntent {
    static var title: LocalizedStringResource = "Order Coffee"
    static var description = IntentDescription("Orders coffee for pickup")

    @Parameter(title: "Coffee Type")
    var coffeeType: CoffeeType

    @Parameter(title: "Size")
    var size: CoffeeSize

    @Parameter(title: "Customizations")
    var customizations: String?

    static var parameterSummary: some ParameterSummary {
        Summary("Order \(\.$size) \(\.$coffeeType)") {
            \.$customizations
        }
    }

    func perform() async throws -> some IntentResult {
        let order = try await CoffeeService.shared.order(
            type: coffeeType,
            size: size,
            customizations: customizations
        )

        return .result(
            value: order,
            dialog: "Your \(size) \(coffeeType) is ordered for pickup"
        )
    }
}

struct ReorderLastIntent: AppIntent {
    static var title: LocalizedStringResource = "Reorder Last Coffee"
    static var description = IntentDescription("Reorders your most recent coffee")
    static var openAppWhenRun: Bool = false

    func perform() async throws -> some IntentResult {
        guard let lastOrder = try await CoffeeService.shared.lastOrder() else {
            throw CoffeeError.noRecentOrders
        }

        try await CoffeeService.shared.reorder(lastOrder)

        return .result(
            dialog: "Reordering your \(lastOrder.coffeeName)"
        )
    }
}

enum CoffeeType: String, AppEnum {
    case latte, cappuccino, americano, espresso

    static var typeDisplayRepresentation: TypeDisplayRepresentation = "Coffee"
    static var caseDisplayRepresentations: [CoffeeType: DisplayRepresentation] = [
        .latte: "Latte",
        .cappuccino: "Cappuccino",
        .americano: "Americano",
        .espresso: "Espresso"
    ]
}

enum CoffeeSize: String, AppEnum {
    case small, medium, large

    static var typeDisplayRepresentation: TypeDisplayRepresentation = "Size"
    static var caseDisplayRepresentations: [CoffeeSize: DisplayRepresentation] = [
        .small: "Small",
        .medium: "Medium",
        .large: "Large"
    ]
}

Step 2: Create AppShortcutsProvider

步骤2:创建AppShortcutsProvider

swift
import AppIntents

struct CoffeeAppShortcuts: AppShortcutsProvider {

    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        // Generic order (will ask for parameters)
        AppShortcut(
            intent: OrderCoffeeIntent(),
            phrases: [
                "Order coffee in \(.applicationName)",
                "Get coffee from \(.applicationName)"
            ],
            shortTitle: "Order",
            systemImageName: "cup.and.saucer.fill"
        )

        // Common specific orders (skip parameter step)
        AppShortcut(
            intent: OrderCoffeeIntent(
                coffeeType: .latte,
                size: .medium
            ),
            phrases: [
                "Order my usual from \(.applicationName)",
                "Get my regular coffee from \(.applicationName)"
            ],
            shortTitle: "Usual Order",
            systemImageName: "star.fill"
        )

        // Reorder last
        AppShortcut(
            intent: ReorderLastIntent(),
            phrases: [
                "Reorder coffee from \(.applicationName)",
                "Order again from \(.applicationName)"
            ],
            shortTitle: "Reorder",
            systemImageName: "arrow.clockwise"
        )
    }

    // Branding
    static var shortcutTileColor: ShortcutTileColor = .tangerine

    // Prevent false positives (iOS 17+)
    static var negativePhrases: [NegativeAppShortcutPhrase] {
        NegativeAppShortcutPhrases {
            "Cancel coffee order"
            "Stop coffee"
        }
    }
}

swift
import AppIntents

struct CoffeeAppShortcuts: AppShortcutsProvider {

    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        // 通用下单快捷方式(会询问参数)
        AppShortcut(
            intent: OrderCoffeeIntent(),
            phrases: [
                "Order coffee in \(.applicationName)",
                "Get coffee from \(.applicationName)"
            ],
            shortTitle: "Order",
            systemImageName: "cup.and.saucer.fill"
        )

        // 常见的特定订单(跳过参数步骤)
        AppShortcut(
            intent: OrderCoffeeIntent(
                coffeeType: .latte,
                size: .medium
            ),
            phrases: [
                "Order my usual from \(.applicationName)",
                "Get my regular coffee from \(.applicationName)"
            ],
            shortTitle: "Usual Order",
            systemImageName: "star.fill"
        )

        // 重新下单
        AppShortcut(
            intent: ReorderLastIntent(),
            phrases: [
                "Reorder coffee from \(.applicationName)",
                "Order again from \(.applicationName)"
            ],
            shortTitle: "Reorder",
            systemImageName: "arrow.clockwise"
        )
    }

    // 品牌化设置
    static var shortcutTileColor: ShortcutTileColor = .tangerine

    // 防止误触发(iOS 17+)
    static var negativePhrases: [NegativeAppShortcutPhrase] {
        NegativeAppShortcutPhrases {
            "Cancel coffee order"
            "Stop coffee"
        }
    }
}

Step 3: Promote in UI

步骤3:在UI中推广

swift
import SwiftUI
import AppIntents

struct OrderConfirmationView: View {
    @State private var showReorderTip = true

    var body: some View {
        VStack(spacing: 20) {
            Image(systemName: "checkmark.circle.fill")
                .font(.system(size: 60))
                .foregroundColor(.green)

            Text("Order Placed!")
                .font(.title)

            Text("Your coffee will be ready in 10 minutes")
                .foregroundColor(.secondary)

            // Promote reorder shortcut
            if showReorderTip {
                SiriTipView(intent: ReorderLastIntent(), isVisible: $showReorderTip)
                    .siriTipViewStyle(.dark)
                    .padding(.top)
            }

            // Link to see all shortcuts
            Section {
                ShortcutsLink()
            } header: {
                Text("See all available shortcuts")
                    .font(.caption)
            }
        }
        .padding()
    }
}

swift
import SwiftUI
import AppIntents

struct OrderConfirmationView: View {
    @State private var showReorderTip = true

    var body: some View {
        VStack(spacing: 20) {
            Image(systemName: "checkmark.circle.fill")
                .font(.system(size: 60))
                .foregroundColor(.green)

            Text("Order Placed!")
                .font(.title)

            Text("Your coffee will be ready in 10 minutes")
                .foregroundColor(.secondary)

            // 推广重新下单快捷方式
            if showReorderTip {
                SiriTipView(intent: ReorderLastIntent(), isVisible: $showReorderTip)
                    .siriTipViewStyle(.dark)
                    .padding(.top)
            }

            // 链接到所有快捷方式
            Section {
                ShortcutsLink()
            } header: {
                Text("See all available shortcuts")
                    .font(.caption)
            }
        }
        .padding()
    }
}

Where App Shortcuts Appear

App Shortcuts的展示位置

Once implemented, your App Shortcuts are available in:
LocationUser Experience
SiriVoice activation with provided phrases
SpotlightSearch for action or phrase → Instant execution
Shortcuts appPre-populated shortcuts, zero configuration
Action Button (iPhone 15 Pro)Assignable to hardware button
Apple Watch UltraAction Button assignment
Control CenterAdd shortcuts as controls
Lock Screen widgetsQuick actions without unlocking
Apple Pencil ProSqueeze gesture assignment
Focus FiltersContextual filtering
Instant availability All locations work immediately after app install. No user setup required.

实现后,你的App Shortcuts会在以下位置可用:
位置用户体验
Siri使用提供的短语语音激活
Spotlight搜索操作或短语 → 即时执行
快捷指令应用预填充快捷方式,零配置
操作按钮(iPhone 15 Pro)可分配给硬件按钮
Apple Watch Ultra操作按钮分配
控制中心添加快捷方式为控件
锁屏小组件无需解锁即可快速操作
Apple Pencil Pro挤压手势分配
专注模式过滤上下文过滤
即时可用:所有位置在应用安装后即可使用,无需用户设置。

Testing & Debugging

测试与调试

Verify Shortcuts Appear in Shortcuts App

验证快捷方式是否在快捷指令应用中显示

  1. Build and run your app on device
  2. Open Shortcuts app
  3. Tap "+" to create new shortcut
  4. Search for your app name
  5. Verify shortcuts appear with correct titles and icons
If shortcuts don't appear:
  • Ensure AppShortcutsProvider is in your main app target
  • Check that
    isDiscoverable
    is true for the AppIntents (default)
  • Rebuild and reinstall app
  • Check console for AppShortcuts errors

  1. 在设备上构建并运行你的应用
  2. 打开快捷指令应用
  3. 点击“+”创建新快捷方式
  4. 搜索你的应用名称
  5. 验证快捷方式是否显示正确的标题和图标
如果快捷方式未显示
  • 确保AppShortcutsProvider在主应用目标中
  • 检查AppIntents的
    isDiscoverable
    是否为true(默认是)
  • 重新构建并重新安装应用
  • 查看控制台中的AppShortcuts错误信息

Test Siri Invocation

测试Siri调用

  1. Invoke Siri
  2. Say one of your suggested phrases
  3. Verify Siri executes the intent
Example:
  • You: "Order coffee in CoffeeApp"
  • Siri: "What size and type?"
  • You: "Medium latte"
  • Siri: "Your medium latte is ordered for pickup"
If Siri doesn't recognize phrase:
  • Check phrase includes
    \(.applicationName)
  • Verify phrase is in appShortcuts array
  • Try simpler phrases (3-6 words ideal)
  • Avoid complex grammar or rare words

  1. 唤起Siri
  2. 说出你的一个建议短语
  3. 验证Siri是否执行了对应的意图
示例
  • 你:"Order coffee in CoffeeApp"
  • Siri:"What size and type?"
  • 你:"Medium latte"
  • Siri:"Your medium latte is ordered for pickup"
如果Siri无法识别短语
  • 检查短语是否包含
    \(.applicationName)
  • 验证短语是否在appShortcuts数组中
  • 尝试更简单的短语(理想长度3-6个单词)
  • 避免复杂语法或生僻词

Test Spotlight Discovery

测试Spotlight可发现性

  1. Swipe down to open Spotlight
  2. Type your app name or shortcut phrase
  3. Verify shortcut appears in results
  4. Tap to execute
If shortcut doesn't appear in Spotlight:
  • Wait a few minutes (indexing delay)
  • Restart device
  • Check System Settings → Siri & Search → [Your App] → Show App in Search

  1. 向下滑动打开Spotlight
  2. 输入你的应用名称或快捷方式短语
  3. 验证快捷方式是否出现在结果中
  4. 点击执行
如果快捷方式未在Spotlight中显示
  • 等待几分钟(索引有延迟)
  • 重启设备
  • 检查系统设置 → Siri与搜索 → [你的应用] → 显示应用在搜索结果中

Debug with Console Logs

使用控制台日志调试

swift
#if DEBUG
struct CoffeeAppShortcuts: AppShortcutsProvider {
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        let shortcuts = [
            AppShortcut(/* ... */),
            // ...
        ]

        print("📱 Registered \(shortcuts.count) App Shortcuts")
        shortcuts.forEach { shortcut in
            print("  - \(shortcut.shortTitle)")
        }

        return shortcuts
    }
}
#endif
Check Xcode console after app launch to verify shortcuts are registered.

swift
#if DEBUG
struct CoffeeAppShortcuts: AppShortcutsProvider {
    @AppShortcutsBuilder
    static var appShortcuts: [AppShortcut] {
        let shortcuts = [
            AppShortcut(/* ... */),
            // ...
        ]

        print("📱 Registered \(shortcuts.count) App Shortcuts")
        shortcuts.forEach { shortcut in
            print("  - \(shortcut.shortTitle)")
        }

        return shortcuts
    }
}
#endif
查看Xcode控制台:应用启动后,验证快捷方式是否已注册。

Best Practices

最佳实践

1. Phrase Design

1. 短语设计

❌ DON'T: Long, complex phrases

❌ 不要:冗长、复杂的短语

swift
phrases: [
    "I would like to order a coffee from \(.applicationName) please"
]
swift
phrases: [
    "I would like to order a coffee from \(.applicationName) please"
]

✅ DO: Short, natural phrases

✅ 要:简短、自然的短语

swift
phrases: [
    "Order coffee in \(.applicationName)",
    "Get coffee from \(.applicationName)"
]
Guidelines:
  • 3-6 words ideal
  • Start with verb (Order, Start, Get, Show)
  • Include
    \(.applicationName)
    for disambiguation
  • Use natural language users would actually say

swift
phrases: [
    "Order coffee in \(.applicationName)",
    "Get coffee from \(.applicationName)"
]
指南
  • 理想长度3-6个单词
  • 以动词开头(Order, Start, Get, Show)
  • 包含
    \(.applicationName)
    以消歧义
  • 使用用户实际会说的自然语言

2. Shortcut Quantity

2. 快捷方式数量

❌ DON'T: Provide 20+ shortcuts

❌ 不要:提供20+个快捷方式

swift
// Bad: Overwhelming
AppShortcut for every possible combination
swift
// 不佳:过于繁杂
为每一种可能的组合创建AppShortcut

✅ DO: Focus on 3-5 core actions

✅ 要:专注于3-5个核心操作

swift
// Good: Focused on common tasks
AppShortcut(intent: OrderIntent(), /* ... */)
AppShortcut(intent: ReorderIntent(), /* ... */)
AppShortcut(intent: ViewOrdersIntent(), /* ... */)
Why Too many shortcuts creates clutter. Focus on high-value, frequently-used actions.

swift
// 良好:聚焦常见任务
AppShortcut(intent: OrderIntent(), /* ... */)
AppShortcut(intent: ReorderIntent(), /* ... */)
AppShortcut(intent: ViewOrdersIntent(), /* ... */)
原因:过多的快捷方式会造成视觉杂乱。聚焦于高价值、高频使用的操作。

3. Parameter Combinations

3. 参数组合

❌ DON'T: Parameterize every variant

❌ 不要:为所有变体添加参数

swift
// Bad: Creates 12 shortcuts (3 sizes × 4 types)
for size in CoffeeSize.allCases {
    for type in CoffeeType.allCases {
        AppShortcut(intent: OrderIntent(type: type, size: size), /* ... */)
    }
}
swift
// 不佳:创建12个快捷方式(3种尺寸 × 4种类型)
for size in CoffeeSize.allCases {
    for type in CoffeeType.allCases {
        AppShortcut(intent: OrderIntent(type: type, size: size), /* ... */)
    }
}

✅ DO: Provide generic + top 2-3 common cases

✅ 要:提供通用版本 + 2-3个常见场景版本

swift
// Good: Generic + common specific cases
AppShortcut(intent: OrderIntent(), /* ... */)  // Generic
AppShortcut(intent: OrderIntent(type: .latte, size: .medium), /* ... */)  // Usual
AppShortcut(intent: OrderIntent(type: .espresso, size: .small), /* ... */)  // Quick

swift
// 良好:通用版本 + 常见特定场景
AppShortcut(intent: OrderIntent(), /* ... */)  // 通用版本
AppShortcut(intent: OrderIntent(type: .latte, size: .medium), /* ... */)  // 常用订单
AppShortcut(intent: OrderIntent(type: .espresso, size: .small), /* ... */)  // 快速订单

4. Short Titles

4. 短标题

❌ DON'T: Verbose or redundant

❌ 不要:冗长或重复

swift
shortTitle: "Order Coffee from Coffee App"
swift
shortTitle: "Order Coffee from Coffee App"

✅ DO: Concise and clear

✅ 要:简洁明了

swift
shortTitle: "Order"
Context App name already appears in Shortcuts app, so no need to repeat.

swift
shortTitle: "Order"
上下文:快捷指令应用中已经显示应用名称,无需重复。

5. System Images

5. 系统图标

❌ DON'T: Use custom images

❌ 不要:使用自定义图标

swift
// Not supported
shortImage: UIImage(named: "custom")
swift
// 不支持
shortImage: UIImage(named: "custom")

✅ DO: Use SF Symbols

✅ 要:使用SF Symbols

swift
systemImageName: "cup.and.saucer.fill"
Why SF Symbols scale properly, support dark mode, and integrate with system UI.

swift
systemImageName: "cup.and.saucer.fill"
原因:SF Symbols可以正确缩放,支持深色模式,并与系统UI完美集成。

Resources

资源

WWDC: 2022-10170, 2022-10169, 260
Docs: /appintents/appshortcutsprovider, /appintents/appshortcut, /appintents/app-shortcuts
Skills: axiom-app-intents-ref, axiom-app-discoverability, axiom-core-spotlight-ref

Remember App Shortcuts make your app's functionality instantly available across iOS. Define 3-5 core shortcuts with natural phrases, promote them in your UI with SiriTipView, and users can invoke them immediately via Siri, Spotlight, Action Button, and more.
WWDC:2022-10170, 2022-10169, 260
文档:/appintents/appshortcutsprovider, /appintents/appshortcut, /appintents/app-shortcuts
技能:axiom-app-intents-ref, axiom-app-discoverability, axiom-core-spotlight-ref

记住:App Shortcuts让你的应用功能在iOS全平台即时可用。定义3-5个核心快捷方式,使用自然短语,通过SiriTipView在应用内推广,用户就能立即通过Siri、Spotlight、操作按钮等方式调用你的应用功能。