← 返回
未分类 中文

Healthkit Code Review

Reviews HealthKit code for authorization patterns, query usage, background delivery, and data type handling. Use when reviewing code with import HealthKit, H...
审查 HealthKit 代码的授权模式、查询使用、后台传递及数据类型处理。适用于审查包含 import HealthKit, H... 的代码
anderskev anderskev 来源
未分类 clawhub v1.2.1 2 版本 99787.2 Key: 无需
★ 0
Stars
📥 469
下载
💾 2
安装
2
版本
#latest

概述

HealthKit Code Review

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

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

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

Review gates

Run in order. Do not state a finding in a later step until the pass condition for the current step is satisfied (each pass condition is answerable from the codebase under review).

  1. ScopePass: Name the file path(s) and types/symbols using HealthKit, HKHealthStore, or HK* APIs (or state clearly that the diff touches none).
  2. Availability and storePass: Cite the call site of isHealthDataAvailable() before HealthKit use, or document why omission is acceptable for the scoped code; cite where HKHealthStore is created or injected.
  3. Authorization semanticsPass: For each requestAuthorization / getRequestStatusForAuthorization, cite handler branches per references/authorization.md (e.g. success does not prove read access); do not infer read permission from authorizationStatus alone.
  4. Queries and limitsPass: For each query, cite predicate + limit (HKObjectQueryNoLimit only with a bounded predicate); for totals/aggregates, cite HKStatisticsQuery / collection vs manual summing per references/queries.md.
  5. Observers and backgroundPass: If HKObserverQuery or enableBackgroundDelivery appears, cite where the observer is started/stopped and where background delivery is registered; cite entitlements/Info.plist or flag missing config per references/background.md. If absent, Pass: one line “no observer/background in scope.”
  6. Threading and lifecyclePass: Cite main-queue (or documented pattern) for UI updates from query callbacks; cite retention/stop()/deinit for long-running queries per checklist above.

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)?

版本历史

共 2 个版本

  • v1.2.1 当前
    2026-05-03 06:43 安全 安全
  • v1.2.0
    2026-03-31 02:47

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

Deepagents Implementation

anderskev
使用 Deep Agents 实现代理,适用于创建代理、配置后端、定义子代理、添加中间件或设置...
★ 0 📥 684
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 181,781
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 677 📥 327,131