简体   繁体   English

如何确定HKQuantitySample数量类型?

[英]How to determine HKQuantitySample quantityType?

I am trying to determine what kind of HKQuantityTypeIdentifier matches the measurements provided in a particular Health Kit sample To determine this, I have tried the following: 我试图确定哪种HKQuantityTypeIdentifier与特定运行状况工具包样本中提供的测量值相匹配。要确定这一点,我尝试了以下方法:

if(hkSample.quantityType == HKQuantityTypeIdentifierDistanceCycling) ...

if([hkSample.quantityType isEqual: HKQuantityTypeIdentifierDistanceCycling]) ...

and

if([hkSample.quantityType isEqualToString: HKQuantityTypeIdentifierDistanceCycling]) ...

The first two options run but give a negative result even when the types should be matching and the last option gives a run-time NSException error for an unknown method. 前两个选项可以运行,但是即使类型应该匹配也可以给出否定的结果,最后一个选项可以为未知方法提供运行时NSException错误。 What's the proper way to determine which type maths an HKQuantitySample type? 确定HKQuantitySample类型的数学类型的正确方法是什么?

quantityType is an HKQuantityType, not a string, so it doesn't respond to -isEqualToString: . quantityType是HKQuantityType,而不是字符串,因此它不会响应-isEqualToString: You need to compare it with another HKQuantityType via -isEqual: , like this: 您需要通过-isEqual:将其与另一个HKQuantityType进行-isEqual: ,如下所示:

if ([hkSample.quantityType isEqual:[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling]])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM