从HealthKit查询获取血糖

时间:2017-02-21 20:56:36

标签: swift health-kit

我正在尝试从查询中提取血糖值,以获得Health App中的最后10个。我可以从Health应用程序中提取数据并将其输入表单中以获取单个条目:

(2017-02-21 13:13:00 -0500 - 2017-02-21 13:13:00 -0500), 80 mg/dL 52D7A973-7853-455C-9308-0E339153A3BE "Health" (10.2.1) metadata: {
HKWasUserEntered = 1;}

我可以通过添加:

从中拉出startdate(和endDate)
guard let timing = reading?.endDate as Date? else {
                print("timing scheme didn't work.")
                return
            }

print(timing)

并通过编写拉

类型(HKQuantityTypeIdentifierBloodGlucose)
guard let bg = reading?.sampleType as HKSampleType? else {
                print("bg scheme didn't work")
                return
            }

print(bg)

但是,我无法弄清楚实际的血糖值(即80 mg / dL)。

我试过了:

let bg = reading.quantity

但是我收到了错误

Value of type 'Optional<HKSample>' has no member 'quantity'

如果有人对此有所了解,那将非常有帮助!提前谢谢!

1 个答案:

答案 0 :(得分:0)

// To read blood glucose:
            let gluco = reading as? HKQuantitySample
            if let bg = gluco?.quantity {
                print(bg)
            }