View in English

  • Apple 开发者
    • 入门汇总

    探索“入门汇总”

    • 概览
    • 学习
    • Apple Developer Program

    及时了解最新动态

    • 最新动态
    • 开发者你好
    • 平台

    探索“平台”

    • Apple 平台
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    • App Store

    精选

    • 设计
    • 分发
    • 游戏
    • 配件
    • 网页
    • Home
    • CarPlay 车载
    • 技术

    探索“技术”

    • 概览
    • Xcode
    • Swift
    • SwiftUI

    精选

    • 辅助功能
    • App Intents
    • Apple 智能
    • 游戏
    • 机器学习与 AI
    • 安全性
    • Xcode Cloud
    • 社区

    探索“社区”

    • 概览
    • “与 Apple 会面交流”活动
    • 社区主导的活动
    • 开发者论坛
    • 开源

    精选

    • WWDC
    • Swift Student Challenge
    • 开发者故事
    • App Store 大奖
    • Apple 设计大奖
    • Apple Developer Centers
    • 文档

    探索“文档”

    • 文档库
    • 技术概述
    • 示例代码
    • 《人机界面指南》
    • 视频

    发布说明

    • 精选更新
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • Apple tvOS
    • Xcode
    • 下载

    探索“下载”

    • 所有下载
    • 操作系统
    • 应用程序
    • 设计资源

    精选

    • Xcode
    • TestFlight
    • 字体
    • SF Symbols
    • Icon Composer
    • 支持

    探索“支持”

    • 概览
    • 帮助指南
    • 开发者论坛
    • “反馈助理”
    • 联系我们

    精选

    • 《开发者账户帮助》
    • 《App 审核指南》
    • 《App Store Connect 帮助》
    • 即将实行的要求
    • 协议和准则
    • 系统状态
  • 快速链接

    • 活动
    • 新闻
    • 论坛
    • 示例代码
    • 视频
 

视频

打开菜单 关闭菜单
  • 专题
  • 所有视频
  • 关于

更多视频

  • 简介
  • 概要
  • 代码
  • 了解全新的 MetricKit

    借助新工具,比以往更快地发现和修复性能问题。与我们一起探索 MetricKit 如何为你提供关键的性能指标和实用的诊断信息,助你精准发现你的 App 在哪些方面仍有改进空间。我们还将介绍如何使用 StateReporting 框架按 App 状态对 App 的指标和诊断信息进行交叉分析,借此全面掌握相关情况,以便进一步排查并优化你 App 的体验。

    章节

    • 0:01 - Introduction
    • 4:07 - Metrics
    • 7:13 - Diagnostics
    • 10:03 - Context

    资源

    • Getting started with StateReporting
    • Analyzing app performance with MetricKit
    • Monitoring app performance with MetricKit
    • Track performance by app state using MetricKit
    • MetricKit
      • 高清视频
      • 标清视频

    相关视频

    WWDC26

    • 性能分析、修复和验证:利用 Instruments 提升 App 响应性
    • 查找并修复 Metal 游戏中的性能问题
  • 搜索此视频…
    • 4:59 - Receive metrics from MetricKit

      // Receive metrics from MetricKit
      
      import MetricKit
      
      let manager = MetricManager()
      
      for await report in manager.metricReports {
          processReport(report)
      }
    • 5:25 - Send your metrics to the server

      // Send your metrics to the server
      
      import MetricKit
      
      for await report in manager.metricReports {
          let jsonData = try JSONEncoder().encode(report)
          sendToServer(jsonData)
      }
    • 5:44 - Access your performance metrics

      // Access your performance metrics
      
      import MetricKit
      
      for await report in manager.metricReports {
          let intervalEntries = report.intervalEntries
          let fullDayEntry = intervalEntries.fullDayEntry
          
          for entry in intervalEntries {
              let memoryMetrics = entry.values.filter { $0.metricGroup == .memory }
              
              for metric in memoryMetrics {
                  switch metric {
                  case .peakMemory(let peak):
                      processPeakMemory(peak)
                  default: break
                  }
              }
          }
      }
    • 8:59 - Receive diagnostics

      // Receive diagnostics
      
      import MetricKit
      
      let manager = MetricManager()
      
      for await report in manager.diagnosticReports {
          processReport(report)
      }
    • 9:14 - Send your diagnostic data to the server

      // Send your diagnostic data to the server
      
      import MetricKit
      
      for await report in manager.diagnosticReports {
          let jsonData = try JSONEncoder().encode(report)
          sendToServer(jsonData)
      }
    • 9:39 - Access your diagnostic data

      // Access your diagnostic data
      
      import MetricKit
      
      for await report in manager.diagnosticReports {
          switch report.result {
          case .crash(let crash):
              let backtrace = crash.callStackTree
              let reason = crash.terminationReason
              let category = crash.terminationCategory
              processCrash(backtrace: backtrace, reason: reason, category: category)
          case .hang(let hang):
              processHangDiagnostic(hang)
          default: break
          }
      }
    • 13:57 - Receive MetricKit data with states

      // Receive MetricKit data with states
      
      import MetricKit
      import StateReporting
      
      let domain = StateReportingDomain("com.metrickitsample.tabs")
      let manager = MetricManager(enabledStateReportingDomains: [domain])
      
      
      // Report transitions throughout the app
      
      let reporter = StateReporter.reporter(for: domain.rawValue)
      reporter.reportTransition(to: "Reports")
    • 14:21 - Define custom structured types

      // Define custom structured types
      
      import StateReporting
      
      @ReportableMetadata
      struct ViewConfiguration {
          let listSize: String
          let isSorted: Bool
      }
      
      let reporter = StateReporter.reporter(
          for: domain.rawValue,
          stableMetadata: ViewConfiguration.self
      )
      
      reporter.reportTransition(
          to: "Reports",
          stableMetadata: ViewConfiguration(listSize: "large", isSorted: false)
      )
    • 15:29 - Send encoded metric reports to the server

      // Send encoded metric reports to the server
      
      import MetricKit
      
      for await report in manager.metricReports {
          let encoder = JSONEncoder()
          
          let formatKey = MetricReport.encodingFormatKey
          encoder.userInfo[formatKey] = MetricReport.EncodingFormat.byStateReportingDomain
          
          let jsonData = try encoder.encode(report)
          sendToServer(jsonData)
      }
    • 0:01 - Introduction
    • MetricKit is a framework that provides metrics and diagnostics for monitoring real-world app performance. In iOS 27, the framework has been rebuilt from the ground up with a new Swift-first API and new features including Metal frame rate metrics, memory exception diagnostics, and granular data with state reporting.

    • 4:07 - Metrics
    • MetricKit delivers daily reports containing performance metrics — including launch time, hangs, CPU, memory, organized into interval entries and metric groups. Metrics can be retrieved as Codable reports for server-side aggregation or inspected directly by filtering for specific groups and values.

    • 7:13 - Diagnostics
    • When an app encounters a crash, hang, or other failure, MetricKit captures and immediately delivers a diagnostic report containing a symbolicated backtrace and metadata such as exception type and termination reason. iOS 27 adds memory exception diagnostics and a new termination category field on crash diagnostics.

    • 10:03 - Context
    • The State Reporting framework lets apps report their active configuration or user flow as named domains and states, which then allows MetricKit to aggregate data separately for each state rather than blending them. Custom structured metadata can be attached to states using the @ReportableMetadata macro, and per-state metrics are surfaced as StateEntry values in the metric report.

Developer Footer

  • 视频
  • WWDC26
  • 了解全新的 MetricKit
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • Apple 智能
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习与 AI
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • 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 Research Device Program (英文)
    打开菜单 关闭菜单
    • 与 Apple 会面交流
    • Apple Developer Center
    • App Store 大奖 (英文)
    • Apple 设计大奖
    • Apple Developer Academies (英文)
    • WWDC
    阅读最近新闻。
    获取 Apple Developer App。
    版权所有 © 2026 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则