简体   繁体   English

来自 HealthKit 的血糖值为零

[英]nil value of Blood Glucose from HealthKit

I've inserted some glucose data in my device health kit app, and now trying to retrieve these inserted data but I'm getting this error:我在我的设备健康套件应用程序中插入了一些葡萄糖数据,现在尝试检索这些插入的数据,但出现此错误:

2015-05-17 11:33:08.056 HKTutorial[687:125911] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to convert incompatible units: mg/dL, mol<180.1558800000541>'

This the method code I'm using to retrieve the glucose data:这是我用来检索葡萄糖数据的方法代码:

func updateGlucose(){    
let sampleType = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBloodGlucose)


self.healthManager?.readMostRecentSample(sampleType, completion: { (mostRecentGluco, error) -> Void in

  if( error != nil )
  {
    println("Error reading blood sugar from HealthKit Store: \(error.localizedDescription)")
    return;
  }

  var glucoLocalizedString = self.kUnknownString;
  // 3. Format the weight to display it on the screen
  self.gluco = mostRecentGluco as? HKQuantitySample;

  if let mmol = self.gluco?.quantity.doubleValueForUnit(HKUnit.moleUnitWithMolarMass(HKUnitMolarMassBloodGlucose)) {
    let glucoFormatter = NSMassFormatter()
    glucoFormatter.forPersonMassUse = true;
    glucoLocalizedString = glucoFormatter.stringForObjectValue(mmol)!
  } else {
    println("error reading glucose data")
  }

  // 4. Update UI in the main thread
  dispatch_async(dispatch_get_main_queue(), { () -> Void in
    self.glucoLabel.text = glucoLocalizedString
    //self.updateBMI()

  });
});
}

The error breaks the code execution precisely at this line:该错误正是在这一行中断了代码执行:

if let mmol = self.gluco?.quantity.doubleValueForUnit(HKUnit.moleUnitWithMolarMass(HKUnitMolarMassBloodGlucose)) {

Any ideas please?请问有什么想法吗?

The problem is that glucose is measured as a concentration but you are converting it to one volume x.问题是葡萄糖是作为浓度测量的,但您将其转换为一个体积 x。 The two units used are mmol/L and mg/dL .使用的两个单位是mmol/Lmg/dL You are converting mg/dL to mol<180.1558800000541> , but instead you should be converting it to mmol/L .您正在将mg/dL转换为mol<180.1558800000541> ,但您应该将其转换为mmol/L

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

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