スライドをクリックでスタート、矢印キーでスライド移動、Escで一覧モードへ戻る

iOS8 β4時点でのHealthKitについて扱う





HKHealthStoreクラスが管理するHKSample
@interface HKSample : HKObject{}HKQuantitySample や HKCategorySample等があるHKQuantitySampleを例にする
NSDate *today = [NSDate date];
double meterValue = 10;
// 単位 = meter
HKUnit *meterUnit = [HKUnit meterUnit];
// 量 = 10
HKQuantity *height = [HKQuantity quantityWithUnit:meterUnit doubleValue:meterValue];
// データ = 種類 + 量 + 単位
HKQuantitySample *heightSample = [HKQuantitySample quantitySampleWithType:heightType
quantity:height
startDate:today endDate:today];

HKQuantitySampleを書き込みするHKHealthStoreクラスが管理する[self.healthStore saveObject:sample withCompletion:^(BOOL success, NSError *error) {
if (!error) {
// 成功
} else {
// 失敗
}
}];

HKQueryクラスで検索条件を作成HKQueryは抽象クラスHKSampleQuery を使って基本的な検索HKQuery に ソートと取得数の制限をつけたサブクラスHKSampleの配列

HKStatistics 
HKStatisticsOptions (統計取得オプション)HKStatisticsHKStatisticsCollectionHKStatistics の配列を持つ
- (void)enumerateStatisticsFromDate:(NSDate *)startDate
toDate:(NSDate *)endDate
withBlock:(void(^)(HKStatistics *result, BOOL *stop))block;

// 1日間隔を表現するNSDateComponents
NSDateComponents *dayComponents = [[NSDateComponents alloc] init];
dayComponents.day = 1;
HKUnit等を使ったローカライズができるsourceを見るsourceでフィルタするメソッドが用意されているHKWorkoutHKBackgroundDelivery