---
title: HealthKitのデータ取得の基本
tags:  #ios #yumemi.grow  
author: [USAMI Kosuke](https://docswell.com/user/usami-k)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/K74WPG25E1.jpg?width=480
description: YUMEMI.grow Mobile #28 - connpass https://yumemi.connpass.com/event/399875/  HealthKitの基本の話をしました #yumemi_grow - usami-kの日記 https://usami-k.hatenablog.com/entry/2026/08/25/202917
published: August 25, 26
canonical: https://docswell.com/s/usami-k/56NLWX-healthkit-overview
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/K74WPG25E1.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
HealthKit のデータ取得の基本
宇佐見公輔
2026-08-25
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
1 / 20


# Page. 2

![Page Image](https://bcdn.docswell.com/page/LJ1Y9DM2EG.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
自己紹介
宇佐見公輔（うさみこうすけ）
iOS アプリエンジニア
ゆめみ（アクセンチュア）
近況
DroidKaigi と iOSDC に参加予定
次の技術書典に向けて準備中
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
2 / 20


# Page. 3

![Page Image](https://bcdn.docswell.com/page/GJWGQY3272.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
今日のテーマ：HealthKit
HealthKit 自体は 10 年以上前からある
最近、ヘルスケアに関心がある
iPhone や Apple Watch でヘルスケア関連のアプリをいくつか使っている
個人的にもアプリを作りたくなったので HealthKit をさわっている
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
3 / 20


# Page. 4

![Page Image](https://bcdn.docswell.com/page/4EZLWXV473.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
Outline
HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
4 / 20


# Page. 5

![Page Image](https://bcdn.docswell.com/page/Y76WG45G7V.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
Outline
HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
5 / 20


# Page. 6

![Page Image](https://bcdn.docswell.com/page/G75MVQYX74.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
HealthKit とは
Apple プラットフォームのヘルスケア情報（健康状態やフィットネス記録）のリ
ポジトリを提供する。
iPhone や Apple Watch で計測されたヘルスケア情報の取得
ヘルスケア情報の書き込み
データへのアクセス権限の管理
データの集計
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
6 / 20


# Page. 7

![Page Image](https://bcdn.docswell.com/page/9J293PGQER.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
対応 OS・デバイス
当初は、iPhone と Apple Watch で利用できた。
iOS 8 以降（2014 年）
watchOS 2 以降（2015 年）
その後、iPad と Apple Vision で利用できるようになった。
iPadOS 17 以降（2023 年）
visionOS 2 以降（2024 年）
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
7 / 20


# Page. 8

![Page Image](https://bcdn.docswell.com/page/DEY415VYJM.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
直接デバイスデータを読むわけではない
どのデバイスのどのセンサーの情報を得るか、というのを指定する形ではない。
ヘルスケア情報のためのリポジトリが提供される
デバイス間の情報同期は iCloud 経由で行われ、内容は全体で統合される
どのデバイスから見ても同じデータが取れる
参考：デバイスからの情報を得たい場合は別のフレームワーク。
Core Motion は HealthKit を経由せずに歩数などがとれる
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
8 / 20


# Page. 9

![Page Image](https://bcdn.docswell.com/page/VJNY2NMR78.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
Outline
HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
9 / 20


# Page. 10

![Page Image](https://bcdn.docswell.com/page/YE9P1RNZJ3.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
HealthKit の有効化
HealthKit の Capability 追加
entitlement が生成される
App ID で有効化する
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
10 / 20


# Page. 11

![Page Image](https://bcdn.docswell.com/page/GE8D4WNYED.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
HealthStore
HealthKit を使う前に、現在のデバイスで利用可能か確認する必要がある。Mac
や iPadOS 16 以前の iPad はここではじかれる。
if HKHealthStore.isHealthDataAvailable() {
// HealthKitが利用可能
}
利用可能であれば、HealthStore のインスタンスを生成する。このインスタンス
は通常アプリ内にひとつだけ生成して利用する。
let healthStore = HKHealthStore()
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
11 / 20


# Page. 12

![Page Image](https://bcdn.docswell.com/page/LELM6NP97R.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
アクセス権限のリクエスト
必要なデータタイプを指定してアクセス権限のリクエストを行う。
try await healthStore.requestAuthorization(toShare: [...], read: [...])
ただし権限の状態を表す HKAuthorizationStatus は 3 つしかない。
case notDetermined
case sharingDenied
case sharingAuthorized
読み取りの可否を表す値がない
requestAuthorization の成功は、許可を意味しない
取得結果が空でも、拒否とデータなしを区別できない
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
12 / 20


# Page. 13

![Page Image](https://bcdn.docswell.com/page/4JMY5X4VJW.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
Outline
HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
13 / 20


# Page. 14

![Page Image](https://bcdn.docswell.com/page/PJR93NWW79.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
取得するデータを指定する
ヘルスケア情報は「データタイプ」ごとに分かれている。取得したいタイプを指定
する。
HKQuantityType：数値で表せるもの（歩数、心拍数、体重）
HKCategoryType：区分で表せるもの（睡眠、月経）
HKCharacteristicType：変化しないもの（生年月日、血液型）
let stepCount = HKQuantityType(.stepCount)
let sleepAnalysis = HKCategoryType(.sleepAnalysis)
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
14 / 20


# Page. 15

![Page Image](https://bcdn.docswell.com/page/PEXQ4NPVJX.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
サンプルを取得する
データタイプと期間を指定してクエリを組み立てる。
let period = HKQuery.predicateForSamples(
withStart: start, end: end, options: []
)
let descriptor = HKSampleQueryDescriptor(
predicates: [.quantitySample(type: stepCount, predicate: period)],
sortDescriptors: [SortDescriptor(\.startDate)],
limit: 100
)
let samples = try await descriptor.result(for: healthStore)
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
15 / 20


# Page. 16

![Page Image](https://bcdn.docswell.com/page/3EK9ZND5ED.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
取得したサンプルから値を取り出す
取得できるのは HKQuantitySample で、値そのものではなく HKQuantity を持つ。
let steps = samples.map { $0.quantity.doubleValue(for: .count()) }
単位を指定して取り出す。合わない単位を渡すと実行時エラーになる
歩数なら count()、体重なら gramUnit(with: .kilo)
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
16 / 20


# Page. 17

![Page Image](https://bcdn.docswell.com/page/L73WDVR175.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
集計して取得する
サンプルを全件取得して自分で合計する必要はない。集計は HealthKit 側ででき
る。
let descriptor = HKStatisticsCollectionQueryDescriptor(
predicate: .quantitySample(type: stepCount),
options: .cumulativeSum,
anchorDate: anchorDate,
intervalComponents: DateComponents(day: 1)
)
let collection = try await descriptor.result(for: healthStore)
let dailySteps = collection.statistics().map { $0.sumQuantity() }
1 日ごとの歩数のように、区間で区切った集計が得られる。
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
17 / 20


# Page. 18

![Page Image](https://bcdn.docswell.com/page/87DKP8YKJG.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
サンプル取得と集計の使い分け
個々の記録が必要なら HKSampleQueryDescriptor
合計や平均だけ必要なら統計クエリ
統計クエリは HKQuantityType 専用で、睡眠などの HKCategoryType には使えない。
集計方法はデータタイプの性質で決まり、合わない組み合わせは例外になる。
歩数のような累積型は、.cumulativeSum
心拍数のような離散型は、.discreteAverage
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
18 / 20


# Page. 19

![Page Image](https://bcdn.docswell.com/page/VJPKN863E8.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
Outline
HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
19 / 20


# Page. 20

![Page Image](https://bcdn.docswell.com/page/2EVVKN3NEQ.jpg)

HealthKit の概要
アプリで HealthKit を使う
データの取得
まとめ
まとめ
HealthKit はヘルスケア情報のリポジトリを提供する
データタイプを指定し、Descriptor でクエリを組んで取得する
集計は HealthKit 側にやらせる
読み取り権限の可否は判定できない前提で設計する
宇佐見公輔
2026-08-25
HealthKit のデータ取得の基本
20 / 20


