healthkit-code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHealthKit Code Review
HealthKit代码审查
Quick Reference
快速参考
| Issue Type | Reference |
|---|---|
| HKHealthStore, permissions, status checks, privacy | references/authorization.md |
| HKQuery types, predicates, anchored queries, statistics | references/queries.md |
| Background delivery, observer queries, completion handlers | references/background.md |
| HKQuantityType, HKCategoryType, workouts, units | references/data-types.md |
| 问题类型 | 参考文档 |
|---|---|
| HKHealthStore、权限、状态检查、隐私 | references/authorization.md |
| HKQuery类型、谓词、锚定查询、统计 | references/queries.md |
| 后台传输、观察者查询、完成处理程序 | references/background.md |
| HKQuantityType、HKCategoryType、运动记录、单位 | references/data-types.md |
Review Checklist
审查检查清单
- called before any HealthKit operations
HKHealthStore.isHealthDataAvailable() - Authorization requested only for needed data types (minimal permissions)
- completion handler not misinterpreted as permission granted
requestAuthorization - No attempt to determine read permission status (privacy by design)
- Query results dispatched to main thread for UI updates
- used only with bounded predicates
HKObjectQueryNoLimit - used for aggregations instead of manual summing
HKStatisticsQuery - Observer query always called (use
completionHandler())defer - Background delivery registered in
application(_:didFinishLaunchingWithOptions:) - Background delivery entitlement added (iOS 15+)
- Correct units used for quantity types (e.g., for heart rate)
count/min - 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 -> background.md
enableBackgroundDelivery - Reviewing HKQuantityType, HKCategoryType, or HKWorkout -> data-types.md
- 审查授权/权限流程 -> authorization.md
- 审查HKSampleQuery、HKAnchoredObjectQuery或谓词 -> queries.md
- 审查HKObserverQuery或-> background.md
enableBackgroundDelivery - 审查HKQuantityType、HKCategoryType或HKWorkout -> data-types.md
Review Questions
审查问题
- Is checked before creating HKHealthStore?
isHealthDataAvailable() - Does the code gracefully handle denied permissions (empty results)?
- Are observer query completion handlers called in all code paths?
- Is work in background handlers minimal (~15 second limit)?
- Are HKQueryAnchors persisted per sample type (not shared)?
- 是否在创建HKHealthStore前检查了?
isHealthDataAvailable() - 代码是否能优雅处理权限被拒绝的情况(返回空结果)?
- 观察者查询的完成处理程序是否在所有代码路径中都被调用?
- 后台处理程序中的任务是否保持最小(约15秒限制)?
- HKQueryAnchor是否按样本类型单独存储(而非共享)?