ios – Question for HeartRates in HealthKit to get each conventional HKQuantitySamples in addition to Cumulative Amount Samples?

0
9


My coronary heart charge question under makes use of the older conventional HKSampleQuery to get coronary heart charges, nonetheless, if an app saves Coronary heart Charges into Apple Well being as a HKCumulativeQuantitySample then my question under does not seize all the coronary heart charges contained in the HKCumulativeQuantitySample. How can I question in order that I seize each kinds of coronary heart charge samples in Apple Well being?

 class func getHeartRateSamplesFrom(exercise: HKWorkout, handler: @escaping ([HKQuantitySample]?, WorkoutManagerError?) -> Void) {
        
        guard let heartRateType:HKQuantityType   = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate) else { return }
        
        //predicate
        let startDate = exercise.startDate
        let endDate = exercise.endDate
        
        let predicate = HKQuery.predicateForSamples(withStart: startDate, finish: endDate, choices: .strictStartDate)
        
        //descriptor
        let sortDescriptors = [
            NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false) 
        ]
        let heartRateQuery = HKSampleQuery(sampleType: heartRateType,
                                           predicate: predicate,
                                           restrict: (HKObjectQueryNoLimit),
                                           sortDescriptors: sortDescriptors)
        { (question:HKSampleQuery, outcomes:[HKSample]?, error:Error?) -> Void in
            
            guard error == nil else { print("get coronary heart charge error"); return }
            
            guard let unwrappedResults = outcomes as? [HKQuantitySample] else { print("get coronary heart charge error"); return}
            handler(unwrappedResults, nil)
            
            
        }
        HealthStoreSingleton.sharedInstance.healthStore.execute(heartRateQuery)
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here