3
私のアプリはHealthKitフレームワークを使用してユーザーの健康状態データを取得します。私は、HealthKitから約25種類のデータポイントを取得したいと考えています。iOSでHealthKitのHKSampleQuery結果を効率的に解析する
これを行うには、サンプルクエリの完了ハンドラ内のfor-loop
に25コールがあります。 結果を組み合わせたり、このプロセスを効率的に行う方法はありますか?。
私の知る限り、これはどのようにしなければならないのですか(下記のコードを参照)。前もって感謝します。
NSDate *startDate, *endDate;
// Use the sample type for step count
HKSampleType *sampleType = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
// Create a predicate to set start/end date bounds of the query
NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
// Create a sort descriptor for sorting by start date
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:HKSampleSortIdentifierStartDate ascending:YES];
HKSampleQuery *sampleQuery = [[HKSampleQuery alloc] initWithSampleType:sampleType predicate:predicate limit:HKObjectQueryNoLimit sortDescriptors:@[sortDescriptor] resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {
if (!error && results) {
for (HKQuantitySample *samples in results) {
// your code here
}
}
}];
// Execute the query
[healthStore executeQuery:sampleQuery];