0
我正面臨着代碼錯誤。以下代碼適用於Apple Health Kit從HealthApp讀取血糖水平。Apple HealthKit血糖水平讀數正在給出轉換錯誤
FUNC updateGluco(){
let sampleType = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBloodGlucose)
self.healthManager?.readMostRecentSample(sampleType, completion: {(mostRecentGluco, error) -> Void in
if (error != nil){
println("Error reading blood glucose from HealthKit store: \(error.localizedDescription)")
return;
}
var glucoLocalizedString = self.kUnknownString;
self.gluco = mostRecentGluco as? HKQuantitySample
println("\(self.gluco?.quantity.doubleValueForUnit(HKUnit.moleUnitWithMolarMass(HKUnitMolarMassBloodGlucose)))")
self.gluco?.quantity.doubleValueForUnit(HKUnit.moleUnitWithMolarMass(HKUnitMolarMassBloodGlucose))
if let mmol = self.gluco?.quantity.doubleValueForUnit(HKUnit.moleUnitWithMolarMass(HKUnitMolarMassBloodGlucose)) {
glucoLocalizedString = "\(mmol)"
} else {
println("error reading gluco data!")
}
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.glucoLabel.text = glucoLocalizedString})
})
}
'NSInvalidArgumentException' 的,原因是: '嘗試不兼容的單位轉換:毫克/分升,摩爾< 180.1558800000541>'
在該行self.gluco?.quantity.doubleValueForUnit(HKUnit.moleUnitWithMolarMass(HKUnitMolarMassBloodGlucose))