用途:在 iOS/Swift 项目中安装并配置 Sentry,实现错误监控、追踪、性能分析、会话回放与日志。适用于用户要求为 iOS 应用添加 Sentry、安装 sentry-cocoa SDK 或配置崩溃上报的场景。
主要能力:支持 Swift Package Manager(推荐)与 CocoaPods 安装;提供 SwiftUI 与 UIKit 两种初始化方式;可配置 DSN、tracesSampleRate、性能分析、会话回放采样率、enableLogs、attachScreenshot、attachViewHierarchy 等选项;自动采集应用启动、网络请求、UI 交互、文件 I/O、Core Data、卡顿帧;支持日志记录、会话回放遮罩、用户上下文设置与错误捕获验证。
使用方式:SPM 添加 https://github.com/getsentry/sentry-cocoa.git,版本规则选 Up to Next Major 从 9.5.0 起,按需选择 Sentry、Sentry-Dynamic、SentrySwiftUI、Sentry-WithoutUIKitOrAppKit 产品。CocoaPods 使用 pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '9.5.0' 后执行 pod install。在 App 初始化中调用 SentrySDK.start 配置选项。体积分析需安装 Fastlane 插件:bundle exec fastlane add_plugin fastlane-plugin-sentry,配置 SENTRY_AUTH_TOKEN 后运行 bundle exec fastlane sentry_size。
适用场景:iOS 15.0+、macOS 12.0+、tvOS 15.0+、watchOS 8.0+ 的 Swift 应用。
限制:资料中的配置选项与代码示例仅为示例,实施前须对照 docs.sentry.io 核实,API 与默认值可能已变化。iOS 26+ 且 Xcode 26+ 时,SDK 8.57.0+ 会自动禁用会话回放,因 Apple Liquid Glass 渲染影响遮罩可靠性;强制启用需 options.experimental.enableSessionReplayInUnreliableEnvironment = true。日志在 SDK 9.0.0+ 用 enableLogs,8.55.0-8.x 用 experimental.enableLogs。具体收费与价格暂未提供。