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
  • Update Live Activities with push notifications

    Discover how you can remotely update Live Activities in your app when you push content through Apple Push Notification service (APNs). We'll show you how to configure your first Live Activity push locally so you can quickly iterate on your implementation. Learn best practices for determining your push priority and configuring alerting updates, and explore how to further improve your Live Activities with relevance score and stale date.

    To get the most out of this session, you should be familiar with ActivityKit and Live Activities. Check out “Meet ActivityKit” for an introduction to Live Activities.

    Capítulos

    • 0:00 - Intro
    • 2:10 - Preparations
    • 5:58 - First push update
    • 11:04 - Priority and alerts
    • 15:40 - Enhancements
    • 17:27 - Wrap-up

    Recursos

    • Sending push notifications using command-line tools
    • Establishing a token-based connection to APNs
    • Human Interface Guidelines: Live Activities
    • Starting and updating Live Activities with ActivityKit push notifications
    • ActivityKit
    • Sending notification requests to APNs
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC24

    • Broadcast updates to your Live Activities

    WWDC23

    • Bring widgets to life
    • Design dynamic Live Activities
    • Meet ActivityKit
  • Buscar neste vídeo...
    • 3:53 - Enabling push updates

      func startActivity(hero: EmojiRanger) throws {
          let adventure = AdventureAttributes(hero: hero)
          let initialState = AdventureAttributes.ContentState(
              currentHealthLevel: hero.healthLevel,
              eventDescription: "Adventure has begun!"
          )
      
          let activity = try Activity.request(
              attributes: adventure,
              content: .init(state: initialState, staleDate: nil),
              pushType: .token
          )
      
          Task {
              for await pushToken in activity.pushTokenUpdates {
                  let pushTokenString = pushToken.reduce("") { $0 + String(format: "%02x", $1) }
                  
                  Logger().log("New push token: \(pushTokenString)")
                  
                  try await self.sendPushToken(hero: hero, pushTokenString: pushTokenString)
              }
          }
      }
    • 6:54 - APNs push payload: Updating

      {
          "aps": {
              "timestamp": 1685952000,
              "event": "update",
              "content-state": {
                  "currentHealthLevel": 0.941,
                  "eventDescription": "Power Panda found a sword!"
              }
          }
      }
    • 7:37 - Printing content state JSON

      let contentState = AdventureAttributes.ContentState(
          currentHealthLevel: 0.941,
          eventDescription: "Power Panda found a sword!"
      )
      
      let encoder = JSONEncoder()
      encoder.outputFormatting = .prettyPrinted
      
      let json = try! encoder.encode(contentState)
      Logger().log("\(String(data: json, encoding: .utf8)!)")
    • 9:18 - Terminal: Constructing an APNs request with curl

      curl \
        --header "apns-topic: com.example.apple-samplecode.Emoji-Rangers.push-type.liveactivity" \
        --header "apns-push-type: liveactivity" \
        --header "apns-priority: 10" \
        --header "authorization: bearer $AUTHENTICATION_TOKEN" \
        --data '{
            "aps": {
                "timestamp": '$(date +%s)',
                "event": "update",
                "content-state": {
                    "currentHealthLevel": 0.941,
                    "eventDescription": "Power Panda found a sword!"
                }
            }
        }' \
        --http2 https://api.sandbox.push.apple.com/3/device/$ACTIVITY_PUSH_TOKEN
    • 14:21 - APNs push payload: Alerting

      {
          "aps": {
              "timestamp": 1685952000,
              "event": "update",
              "content-state": {
                  "currentHealthLevel": 0.0,
                  "eventDescription": "Power Panda has been knocked down!"
              },
              "alert": {
                  "title": "Power Panda is knocked down!",
                  "body": "Use a potion to heal Power Panda!",
                  "sound": "default"
              }
          }
      }
    • 14:56 - APNs push payload: Alert localization

      {
          "aps": {
              "timestamp": 1685952000,
              "event": "update",
              "content-state": {
                  "currentHealthLevel": 0.0,
                  "eventDescription": "Power Panda has been knocked down!"
              },
              "alert": {
                  "title": {
                      "loc-key": "%@ is knocked down!",
                      "loc-args": ["Power Panda"]
                  },
                  "body": {
                      "loc-key": "Use a potion to heal %@!",
                      "loc-args": ["Power Panda"]
                  },
                  "sound": "HeroDown.mp4"
              }
          }
      }
    • 15:25 - APNs push payload: Alert sound

      {
          "aps": {
              "timestamp": 1685952000,
              "event": "update",
              "content-state": {
                  "currentHealthLevel": 0.0,
                  "eventDescription": "Power Panda has been knocked down!"
              },
              "alert": {
                  "title": {
                      "loc-key": "%@ is knocked down!",
                      "loc-args": ["Power Panda"]
                  },
                  "body": {
                      "loc-key": "Use a potion to heal %@!",
                      "loc-args": ["Power Panda"]
                  },
                  "sound": "HeroDown.mp4"
              }
          }
      }
    • 15:52 - APNs push payload: Dismissal

      {
          "aps": {
              "timestamp": 1685952000,
              "event": "end",
              "dismissal-date": 1685959200,
              "content-state": {
                  "currentHealthLevel": 0.23,
                  "eventDescription": "Adventure over! Power Panda is taking a nap."
              }
          }
      }
    • 16:44 - APNs push payload: Stale date

      {
          "aps": {
              "timestamp": 1685952000,
              "event": "update",
              "stale-date": 1685959200,
              "content-state": {
                  "currentHealthLevel": 0.79,
                  "eventDescription": "Egghead is in the woods and lost connection."
              }
          }
      }
    • 16:54 - Displaying a stale Live Activity UI

      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.gameWidgetBackground)
              }  dynamicIsland: { context in
                  // ...
              }
              
          }
          
      }
    • 17:19 - APNs push payload: Relevance score

      {
          "aps": {
              "timestamp": 1685952000,
              "event": "update",
              "relevance-score": 100,
              "content-state": {
                  "currentHealthLevel": 0.941,
                  "eventDescription": "Power Panda found a sword!"
              }
          }
      }

Developer Footer

  • Vídeos
  • WWDC23
  • Update Live Activities with push notifications
  • 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