View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • Implement App Shortcuts with App Intents

    Discover how you can create Shortcuts in your app with zero user setup. We'll show you how App Intents can help you present custom Shortcuts views, and explore how you can add support for parameterized phrases to allow people to quickly express their intent. We'll also share how you can make your App Shortcuts discoverable with a Siri Tip, and Shortcuts links.

    To get the most out of this session, we recommend a basic familiarity with SwiftUI.

    Recursos

    • App Intents
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    Tech Talks

    • Migrate custom intents to App Intents
    • What's new for enterprise developers

    WWDC22

    • Design App Shortcuts
    • Dive into App Intents
  • Buscar neste vídeo...
    • 3:43 - Implement an AppIntent

      // StartMeditationIntent creates a meditation session.
      
      import AppIntents
      
      struct StartMeditationIntent: AppIntent {
          static let title: LocalizedStringResource = "Start Meditation Session"
      
          func perform() async throws -> some IntentResult & ProvidesDialog {
              await MeditationService.startDefaultSession()
              return .result(dialog: "Okay, starting a meditation session.")
          }
      }
    • 5:31 - Create an AppShortcutsProvider

      // An AppShortcut turns an Intent into a full fledged shortcut
      // AppShortcuts are returned from a struct that implements the AppShortcuts
      // protocol
      
      import AppIntents
      
      struct MeditationShortcuts: AppShortcutsProvider {
          static var appShortcuts: [AppShortcut] {
              AppShortcut(
                  intent: StartMeditationIntent(),
                  phrases: ["Start a \(.applicationName)"]
              )
          }
      }
    • 6:35 - Provide multiple phrases

      // An AppShortcut turns an Intent into a full fledged shortcut
      // AppShortcuts are returned from a struct that implements the AppShortcuts
      // protocol
      
      import AppIntents
      
      struct MeditationShortcuts: AppShortcutsProvider {
          static var appShortcuts: [AppShortcut] {
              AppShortcut(
                  intent: StartMeditationIntent(),
                  phrases: [
                      "Start a \(.applicationName)",
                      "Begin \(.applicationName)",
                      "Meditate with \(.applicationName)",
                      "Start a session with \(.applicationName)"
                  ]
              )
          }
      }
    • 8:54 - Provide a dialog and snippet view

      // Custom views give your intent more personality
      // and can convey more information
      
      func perform() async throws -> some ProvidesDialog & ShowsSnippetView {
          await MeditationService.startDefaultSession()
      
          return .result(
              dialog: "Okay, starting a meditation session.",
              view: MeditationSnippetView()
          )
      }
    • 10:09 - Implement an AppEntity

      // An entity is a type that can be used as a parameter
      // for an AppIntent.
      
      import AppIntents
      
      struct MeditationSession: AppEntity {
          let id: UUID
          let name: LocalizedStringResource
      
          static var typeDisplayName: LocalizedStringResource = "Meditation Session"
          var displayRepresentation: AppIntents.DisplayRepresentation {
              DisplayRepresentation(title: name)
          }
      
          static var defaultQuery = MeditationSessionQuery()
      }
    • 10:55 - Query for entities

      // Queries allow the App Intents framework to
      // look up your entities by their identifier
      
      struct MeditationSessionQuery: EntityQuery {
          func entities(for identifiers: [UUID]) async throws -> [MeditationSession] {
              return identifiers.compactMap { SessionManager.session(for: $0) }
          }
      }
    • 11:16 - Define a parameter

      // Adding a parameter to an intent allows you to prompt the user
      // to provide a value for the parameter
      
      struct StartMeditationIntent: AppIntent {
      
          @Parameter(title: "Session Type")
          var sessionType: SessionType?
      
          // ...
      
      }
    • 13:15 - Prompt for values

      // Prompting for values can be done by calling methods
      // on the property's wrapper type.
      
      func perform() async throws -> some ProvidesDialog {
          let sessionToRun = self.session ?? try await $session.requestDisambiguation(
                 among: SessionManager.allSessions,
                 dialog: IntentDialog("What session would you like?")
             )
          }
          await MeditationService.start(session: sessionToRun)
          return .result(
             dialog: "Okay, starting a \(sessionToRun.name) meditation session."
          )
      }
    • 16:11 - Implement suggestedEntities()

      // Queries can provide suggested values for your Entity
      // that serve as parameters for App Shortcuts
      
      struct MeditationSessionQuery: EntityQuery {
          func entities(for identifiers: [UUID]) async throws -> [MeditationSession] {
              return identifiers.compactMap { SessionManager.session(for: $0) }
          }
      
          func suggestedEntities() async throws -> [MeditationSession] {
              return SessionManager.allSessions
          }
      }
    • 16:34 - Update App Shortcut parameters

      // Your app must notify App Intents when your values change
      // This is typically best done in your app’s model layer
      
      class SessionModel {
          @Published
          var sessions: [MeditationSession] = []
          private var cancellable: AnyCancellable?
      
          init() {
              self.cancellable = $sessions.sink { _ in
                  MeditationShortcuts.updateAppShortcutParameters()
              }
          }
      
          // ...
      
      }
    • 17:09 - Add parameterized phrases

      // Phrases can also contain a single parameter reference
      
      import AppIntents
      
      struct MeditationShortcuts: AppShortcutsProvider {
          static var appShortcuts: [AppShortcut] {
              AppShortcut(
                  intent: StartMeditationIntent(),
                  phrases: [
                      "Start a \(.applicationName)",
                      "Begin \(.applicationName)",
                      "Meditate with \(.applicationName)",
                      "Start a \(\.$session) session with \(.applicationName)",
                      "Begin a \(\.$session) session with \(.applicationName)",
                      "Meditate on \(\.$session) with \(.applicationName)"
                  ]
              )
          }
      }

Developer Footer

  • Vídeos
  • WWDC22
  • Implement App Shortcuts with App Intents
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines