watchos-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

watchOS Code Review

watchOS代码审查

Quick Reference

快速参考

Issue TypeReference
App lifecycle, scenes, background modes, extended runtimereferences/lifecycle.md
ClockKit, WidgetKit, timeline providers, Smart Stackreferences/complications.md
WCSession, message passing, file transfer, reachabilityreferences/connectivity.md
Memory limits, background refresh, battery optimizationreferences/performance.md
问题类型参考链接
应用生命周期、场景、后台模式、扩展运行时references/lifecycle.md
ClockKit、WidgetKit、时间线提供器、智能堆栈references/complications.md
WCSession、消息传递、文件传输、可达性references/connectivity.md
内存限制、后台刷新、电池优化references/performance.md

Review Checklist

审查清单

  • SwiftUI App protocol used with
    @WKApplicationDelegateAdaptor
    for lifecycle events
  • scenePhase
    read from root view (not sheets/modals where it's always
    .active
    )
  • WKExtendedRuntimeSession
    started only while app is active (not from background)
  • Workout sessions recovered in
    applicationDidFinishLaunching
    (not just delegate)
  • Background tasks scheduled at least 5 minutes apart; next scheduled before completing current
  • URLSessionDownloadTask
    (not
    DataTask
    ) used for background network requests
  • WidgetKit used instead of ClockKit for watchOS 9+ complications
  • Timeline includes future entries (not just current state); gaps avoided
  • TimelineEntryRelevance
    implemented for Smart Stack prioritization
  • WCSession delegate set before
    activate()
    ; singleton pattern used
  • isReachable
    checked before
    sendMessage
    ;
    transferUserInfo
    for critical data
  • Received files moved synchronously before delegate callback returns
  • 使用带有
    @WKApplicationDelegateAdaptor
    的SwiftUI App协议处理生命周期事件
  • 从根视图读取
    scenePhase
    (而非始终为
    .active
    的弹窗/模态视图)
  • 仅在应用处于活跃状态时启动
    WKExtendedRuntimeSession
    (而非从后台启动)
  • applicationDidFinishLaunching
    中恢复锻炼会话(而非仅通过委托)
  • 后台任务调度间隔至少5分钟;在完成当前任务前调度下一个任务
  • 后台网络请求使用
    URLSessionDownloadTask
    (而非
    DataTask
  • 对于watchOS 9+的复杂功能,使用WidgetKit而非ClockKit
  • 时间线包含未来条目(而非仅当前状态);避免出现间隔
  • 实现
    TimelineEntryRelevance
    以支持智能堆栈优先级排序
  • 在调用
    activate()
    前设置WCSession委托;使用单例模式
  • 调用
    sendMessage
    前检查
    isReachable
    ;对关键数据使用
    transferUserInfo
  • 在委托回调返回前同步移动接收的文件

When to Load References

何时加载参考文档

  • Reviewing app lifecycle, background modes, or extended sessions -> lifecycle.md
  • Reviewing complications, widgets, or timeline providers -> complications.md
  • Reviewing WCSession, iPhone-Watch communication -> connectivity.md
  • Reviewing memory, battery, or performance issues -> performance.md
  • 审查应用生命周期、后台模式或扩展会话时 -> lifecycle.md
  • 审查复杂功能、小组件或时间线提供器时 -> complications.md
  • 审查WCSession、iPhone-Apple Watch通信时 -> connectivity.md
  • 审查内存、电池或性能问题时 -> performance.md

Review Questions

审查问题

  1. Is the app using modern SwiftUI lifecycle with delegate adaptor?
  2. Are background tasks completing properly (calling
    setTaskCompletedWithSnapshot
    )?
  3. Is UI update frequency reduced when
    isLuminanceReduced
    is true?
  4. Are WatchConnectivity delegate callbacks dispatching to main thread?
  5. Is
    TabView
    nested within another
    TabView
    ? (Memory leak on watchOS)
  1. 应用是否使用带有委托适配器的现代SwiftUI生命周期?
  2. 后台任务是否正确完成(调用
    setTaskCompletedWithSnapshot
    )?
  3. isLuminanceReduced
    为true时,是否降低了UI更新频率?
  4. WatchConnectivity委托回调是否调度到主线程?
  5. 是否在另一个
    TabView
    中嵌套了
    TabView
    ?(watchOS上会导致内存泄漏)