简体   繁体   English

读取血压时,HealthKit始终不返回任何结果

[英]HealthKit Always Returns No Results when reading Blood Pressure

I have been trying various options to get results back, but no luck. 我一直在尝试各种选择来恢复结果,但是没有运气。 I took the code from another question and tried to make it work, but still nothing. 我从另一个问题中获取了代码,并试图使其正常运行,但仍然一无所获。 I manually entered the data into health as well as took readings from a BP monitor, so I know there is data there. 我手动将数据输入健康状态,并从BP监视器获取读数,所以我知道那里有数据。 No errors reported. 没有错误报告。

    func readSampleByBloodPressure()
        {
            let past = Date.distantPast
            let now   = Date()
            let sortDescriptor = NSSortDescriptor(key:HKSampleSortIdentifierStartDate, ascending: true)
            let type = HKQuantityType.correlationType(forIdentifier: HKCorrelationTypeIdentifier.bloodPressure)
            let sampleQuery = HKSampleQuery(sampleType: type!, predicate: nil, limit: 0, sortDescriptors: [sortDescriptor])
            { (sampleQuery, results, error ) -> Void in

                let dataLst = results as? [HKCorrelation];

                for data in dataLst!
                {

                    let data1 = (data.objects(for: HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureSystolic)!)).first as? HKQuantitySample
                    let data2 = data.objects(for: HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureDiastolic)!).first as? HKQuantitySample
                print("Data Found")
                /*
                    if let value1 = data1!.quantity.doubleValue(for:     HKUnit.millimeterOfMercury()) , let value2 = data2!.quantity.doubleValue(for: HKUnit.millimeterOfMercury())
                    {
                        print(value1)
                        print(value2)
                    }
                     */
                }

            }
            self.healthStore?.execute(sampleQuery)
        }
}

This is caused by failing to authorize both systolic and diastolic blood pressure readings. 这是由于未能授权收缩压和舒张压读数所致。 In the authorization, when you get the popup from Health Kit, even though you select Authorize All, All implies only what is showing in the list presented, not everything HealthKit has available. 在授权中,当您从Health Kit中获得弹出窗口时,即使选择“全部授权”,“ All”也仅表示显示的列表中显示的内容,而不是HealthKit可用的所有内容。 In your auth code, you need to specify each thing you wish, which will then show up on the auth popup. 在您的身份验证代码中,您需要指定您想要的每件事,然后将它们显示在身份验证弹出窗口中。

As a side note. 作为旁注。 If you have done this and if you check in the health app and see that what you want is authorized and it still isn't working, try toggling the setting. 如果您已执行此操作,并且在运行状况应用程序中签入并看到所需的内容已被授权但仍然无法使用,请尝试切换设置。 Apparently, the initial approval doesn't always take. 显然,最初的批准并不总是需要的。

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

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