WWDC 2014 の「Fit」の例を実行して、HealthKit をチェックしようとしています。iOS8 beta3にアップデートしたiPad airを使用しています。ただし、情報を入力すると、次のエラーでアプリがクラッシュします。
Error Domain=com.apple.healthkit Code=1 "Health data is unavailable on this device"
エラーを生成するメソッドの例を次に示します
- (void)saveHeightIntoHealthStore:(double)height {
// Save the user's height into HealthKit.
HKUnit *inchUnit = [HKUnit inchUnit];
HKQuantity *heightQuantity = [HKQuantity quantityWithUnit:inchUnit doubleValue:height];
HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
NSDate *now = [NSDate date];
HKQuantitySample *heightSample = [HKQuantitySample quantitySampleWithType:heightType quantity:heightQuantity startDate:now endDate:now];
[self.healthStore saveObject:heightSample withCompletion:^(BOOL success, NSError *error) {
if (!success) {
//Error reported here
NSLog(@"An error occured saving the height sample %@. In your app, try to handle this gracefully. The error was: %@.", heightSample, error);
abort();
}
[self updateUsersHeight];
}];
}