healthkit-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

HealthKit Code Review

HealthKit代码审查

Quick Reference

快速参考

Issue TypeReference
HKHealthStore, permissions, status checks, privacyreferences/authorization.md
HKQuery types, predicates, anchored queries, statisticsreferences/queries.md
Background delivery, observer queries, completion handlersreferences/background.md
HKQuantityType, HKCategoryType, workouts, unitsreferences/data-types.md
问题类型参考文档
HKHealthStore、权限、状态检查、隐私references/authorization.md
HKQuery类型、谓词、锚定查询、统计references/queries.md
后台传输、观察者查询、完成处理程序references/background.md
HKQuantityType、HKCategoryType、运动记录、单位references/data-types.md

Review Checklist

审查检查清单

  • HKHealthStore.isHealthDataAvailable()
    called before any HealthKit operations
  • Authorization requested only for needed data types (minimal permissions)
  • requestAuthorization
    completion handler not misinterpreted as permission granted
  • No attempt to determine read permission status (privacy by design)
  • Query results dispatched to main thread for UI updates
  • HKObjectQueryNoLimit
    used only with bounded predicates
  • HKStatisticsQuery
    used for aggregations instead of manual summing
  • Observer query
    completionHandler()
    always called (use
    defer
    )
  • Background delivery registered in
    application(_:didFinishLaunchingWithOptions:)
  • Background delivery entitlement added (iOS 15+)
  • Correct units used for quantity types (e.g.,
    count/min
    for heart rate)
  • Long-running queries stored as properties and stopped in
    deinit
  • 在执行任何HealthKit操作前调用
    HKHealthStore.isHealthDataAvailable()
  • 仅为所需数据类型请求授权(最小权限原则)
  • 未将
    requestAuthorization
    的完成处理程序错误解读为权限已授予
  • 未尝试判断读取权限状态(隐私设计原则)
  • 查询结果已分发至主线程以更新UI
  • HKObjectQueryNoLimit
    仅与有限制的谓词配合使用
  • 使用
    HKStatisticsQuery
    进行聚合计算而非手动求和
  • 观察者查询的
    completionHandler()
    始终被调用(使用
    defer
  • application(_:didFinishLaunchingWithOptions:)
    中注册后台传输
  • 添加了后台传输权限(iOS 15+)
  • 为数量类型使用了正确的单位(例如,心率使用
    count/min
  • 长期运行的查询已存储为属性并在
    deinit
    中停止

When to Load References

何时查阅参考文档

  • Reviewing authorization/permissions flow -> authorization.md
  • Reviewing HKSampleQuery, HKAnchoredObjectQuery, or predicates -> queries.md
  • Reviewing HKObserverQuery or
    enableBackgroundDelivery
    -> background.md
  • Reviewing HKQuantityType, HKCategoryType, or HKWorkout -> data-types.md
  • 审查授权/权限流程 -> authorization.md
  • 审查HKSampleQuery、HKAnchoredObjectQuery或谓词 -> queries.md
  • 审查HKObserverQuery或
    enableBackgroundDelivery
    -> background.md
  • 审查HKQuantityType、HKCategoryType或HKWorkout -> data-types.md

Review Questions

审查问题

  1. Is
    isHealthDataAvailable()
    checked before creating HKHealthStore?
  2. Does the code gracefully handle denied permissions (empty results)?
  3. Are observer query completion handlers called in all code paths?
  4. Is work in background handlers minimal (~15 second limit)?
  5. Are HKQueryAnchors persisted per sample type (not shared)?
  1. 是否在创建HKHealthStore前检查了
    isHealthDataAvailable()
  2. 代码是否能优雅处理权限被拒绝的情况(返回空结果)?
  3. 观察者查询的完成处理程序是否在所有代码路径中都被调用?
  4. 后台处理程序中的任务是否保持最小(约15秒限制)?
  5. HKQueryAnchor是否按样本类型单独存储(而非共享)?