我正在尝试运行 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];
}];
}