我能够使用锻炼 class 访问锻炼数据,但无法与其他人进行相同的操作,例如访问身高,体重,饮食水,体温,血压等。
我也可以获取心率,但无法获取体温。它们都是相同的生命体征标识符。
手表只能访问WWDC 2015视频中提到的锻炼数据吗?
示例代码:
-(void)bodyTempForLabel :(WKInterfaceLabel *)bodyTempLabel {
HKSampleType *bodyTemp = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyTemperature];
[self readMostRecentSampleType:bodyTemp withCompletion:^(HKQuantitySample *quantitySample, NSError *error) {
if(error) {
NSLog(@"Error Reading Weight From health Kit");
}
self.bodyTemp = quantitySample;
double bodyTempinDegree = [[self.bodyTemp quantity] doubleValueForUnit:[HKUnit unitFromString:[NSString stringWithFormat:@"%@C", @"\u00B0"]]];
dispatch_async(dispatch_get_main_queue(), ^{
[bodyTempLabel setText:[NSString stringWithFormat:@"%f",bodyTempinDegree]];
});
}];
}
-(void)readMostRecentSampleType : (HKSampleType *)sampleType withCompletion:(void(^)(HKQuantitySample *quantitySample,NSError *error))recentSample {
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:HKSampleSortIdentifierEndDate ascending:NO];
HKQuery *sampleQuery = [[HKSampleQuery alloc] initWithSampleType:sampleType predicate:nil limit:HKObjectQueryNoLimit sortDescriptors:@[sortDescriptor] resultsHandler:^(HKSampleQuery * _Nonnull query, NSArray<__kindof HKSample *> * _Nullable results, NSError * _Nullable error) {
if(!error) {
// No results retuned array empty
HKQuantitySample *mostRecentSample = results.firstObject;
recentSample(mostRecentSample,error);
}
}];
[_healthStore executeQuery:sampleQuery];
}
任何帮助,将不胜感激。谢谢!!!
最佳答案
看来您需要使用真实的设备进行调试。运行模拟器时,我无法从香港获得任何价值,但在Apple Watch中可以正常使用。 (使用XCode 7 Beta 5)。
关于ios - 将Health Kit数据(锻炼数据除外)访问到Apple Watch OS 2中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31990017/