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
 

Vidéos

Ouvrir le menu Fermer le menu
  • Collections
  • Toutes les vidéos
  • À propos

Plus de vidéos

  • À propos
  • Code
  • Meet ActivityKit

    Live Activities are a glanceable way for someone to keep track of the progress of a task within your app. We'll teach you how you can create helpful experiences for the Lock Screen, the Dynamic Island, and StandBy. Learn how to update your app's Live Activities, monitor activity state, and take advantage of WidgetKit and SwiftUI to build richer experiences.

    Chapitres

    • 0:00 - Intro
    • 0:36 - Live Activity overview
    • 4:23 - Lifecycle of Live Activities
    • 10:43 - Building Live Activity UI
    • 16:37 - Wrap-up

    Ressources

    • Human Interface Guidelines: Live Activities
    • Starting and updating Live Activities with ActivityKit push notifications
    • Displaying live data with Live Activities
    • ActivityKit
    • WidgetKit
      • Vidéo HD
      • Vidéo SD

    Vidéos connexes

    WWDC23

    • Bring widgets to life
    • Design dynamic Live Activities
    • Update Live Activities with push notifications
  • Rechercher dans cette vidéo…
    • 5:40 - Define ActivityAttributes

      import ActivityKit
      
      struct AdventureAttributes: ActivityAttributes {
          let hero: EmojiRanger
      
          struct ContentState: Codable & Hashable {
              let currentHealthLevel: Double
              let eventDescription: String
          }
      }
    • 6:28 - Request Live Activity with initial content state

      let adventure = AdventureAttributes(hero: hero)
      
      let initialState = AdventureAttributes.ContentState(
          currentHealthLevel: hero.healthLevel,
          eventDescription: "Adventure has begun!"
      )
      let content = ActivityContent(state: initialState, staleDate: nil, relevanceScore: 0.0)
      
      let activity = try Activity.request(
          attributes: adventure,
          content: content,
          pushType: nil
      )
    • 8:00 - Update Live Activity with new content

      let heroName = activity.attributes.hero.name               
      let contentState = AdventureAttributes.ContentState(
          currentHealthLevel: hero.healthLevel,
          eventDescription: "\(heroName) has taken a critical hit!"
      )
      
      var alertConfig = AlertConfiguration(
          title: "\(heroName) has taken a critical hit!",
          body: "Open the app and use a potion to heal \(heroName)",
          sound: .default
      )  
           
      activity.update(
          ActivityContent<AdventureAttributes.ContentState>(
              state: contentState,
              staleDate: nil
          ),
          alertConfiguration: alertConfig
      )
    • 9:30 - Observe activity state

      // Observe activity state asynchronously
      func observeActivity(activity: Activity<AdventureAttributes>) {
          Task {
              for await activityState in activity.activityStateUpdates {
                  if activityState == .dismissed {
                      self.cleanUpDismissedActivity()
                  }
              }
          }
      }
      
      // Observe activity state synchronously
      let activityState = activity.activityState
      if activityState == .dismissed {
          self.cleanUpDismissedActivity()
      }
    • 10:03 - Dismiss Live Activity with final content state

      let hero = activity.attributes.hero
      
      let finalContent = AdventureAttributes.ContentState(
          currentHealthLevel: hero.healthLevel,
          eventDescription: "Adventure over! \(hero.name) has defeated the boss! Congrats!"
      )
      
      let dismissalPolicy: ActivityUIDismissalPolicy = .default
      
      activity.end(
          ActivityContent(state: finalContent, staleDate: nil),
          dismissalPolicy: dismissalPolicy)
      }
    • 10:50 - Add ActivityConfiguration to WidgetBundle

      import WidgetKit
      import SwiftUI
      
      @main
      struct EmojiRangersWidgetBundle: WidgetBundle {
          var body: some Widget {
              EmojiRangerWidget()
              LeaderboardWidget()
              AdventureActivityConfiguration()
          }
      }
    • 11:05 - Define Lock Screen presentation

      struct AdventureActivityConfiguration: Widget {
          var body: some WidgetConfiguration {
              ActivityConfiguration(for: AdventureAttributes.self) { context in
                  AdventureLiveActivityView(
                      hero: context.attributes.hero,
                      isStale: context.isStale,
                      contentState: context.state
                  )
                  .activityBackgroundTint(Color.navyBlue)
              } dynamicIsland: { context in
                  // ...
              }
          }
      }
    • 13:28 - Define Dynamic Island compact presentation

      struct AdventureActivityConfiguration: Widget {
          var body: some WidgetConfiguration {
              ActivityConfiguration(for: AdventureAttributes.self) { context in
                  // ...
              } dynamicIsland: { context in
                  DynamicIsland {
                      // ...
                  } compactLeading: {
                      Avatar(hero: context.attributes.hero)
                  } compactTrailing: {
                      ProgressView(value: context.state.currentHealthLevel) {
                          Text("\(Int(context.state.currentHealthLevel * 100))")
                      }
                      .progressViewStyle(.circular)
                      .tint(context.state.currentHealthLevel <= 0.2 ? Color.red : Color.green)
                  } minimal: {
                      // ...
                  }
              }
          }
      }
    • 14:42 - Define Dynamic Island minimal presentation

      struct AdventureActivityConfiguration: Widget {
          var body: some WidgetConfiguration {
              ActivityConfiguration(for: AdventureAttributes.self) { context in
                  // ...
              } dynamicIsland: { context in
                  DynamicIsland {
                      // ...
                  } compactLeading: {
                      // ...
                  } compactTrailing: {
                      // ...
                  } minimal: {
                      ProgressView(value: context.state.currentHealthLevel) {
                          Avatar(hero: context.attributes.hero)
                      }
                      .progressViewStyle(.circular)
                      .tint(context.state.currentHealthLevel <= 0.2 ? Color.red : Color.green)
                  }
              }
          }
      }
    • 15:26 - Define Dynamic Island expanded presentation

      struct AdventureActivityConfiguration: Widget {
          var body: some WidgetConfiguration {
              ActivityConfiguration(for: AdventureAttributes.self) { context in
                  // ...
              } dynamicIsland: { context in
                  DynamicIsland {
                      // Leading region
                      DynamicIslandExpandedRegion(.leading) {
                          LiveActivityAvatarView(hero: hero)
                      }
      
                      // Expanded region
                      DynamicIslandExpandedRegion(.trailing) {
                          StatsView(hero: hero, isStale: isStale)
                      }
      
                      // Bottom region
                      DynamicIslandExpandedRegion(.bottom) {
                          HealthBar(currentHealthLevel: contentState.currentHealthLevel)
                          EventDescriptionView(hero: hero, contentState: contentState)
                      }
                  } compactLeading: {
                      // ...
                  } compactTrailing: {
                      // ...
                  } minimal: {
                      // ...
                  }
              }
          }
      }

Developer Footer

  • Vidéos
  • WWDC23
  • Meet ActivityKit
  • 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