HomeiOS Developmentios - How can I get the best pattern charge historic coronary...

ios – How can I get the best pattern charge historic coronary heart charge knowledge from well being retailer?


I’m attempting to get coronary heart charge knowledge from well being retailer however after I make a question there are samples that come by means of with timestamps that reveals that there are minutes that go by between the pattern measurements. I bear in mind watching an apple video the place they have been speaking concerning the Amount collection and the way these collection have one sort of container for a number of knowledge factors of bpm knowledge. I additionally see within the samples that there’s a unit of ” ___ counts per second” for every of the outcomes so it might make sense if there have been a number of datapoints inside every of the outcomes from the question however I do not know learn how to see what’s inside the outcomes or if there’s even something extra to them.

That is the code I’m utilizing to retrieve the info:

public func fetchLatestHeartRateSample(completion: @escaping (_ samples: [HKQuantitySample]?) -> Void) {

    /// Create pattern kind for the guts charge
    guard let sampleType = HKObjectType
      .quantityType(forIdentifier: .heartRate) else {
        completion(nil)
      return
    }

    /// Predicate for specifying begin and finish dates for the question
    let predicate = HKQuery
      .predicateForSamples(
        withStart: Date.distantPast,
        finish: Date(),
        choices: .strictEndDate)

    /// Set sorting by date.
    let sortDescriptor = NSSortDescriptor(
      key: HKSampleSortIdentifierStartDate,
      ascending: false)

    /// Create the question
    let question = HKSampleQuery(
      sampleType: sampleType,
      predicate: predicate,
      restrict: Int(HKObjectQueryNoLimit),
      sortDescriptors: [sortDescriptor]) { ( _, outcomes, error) in

      guard error == nil else {
        print("Error: (error!.localizedDescription)")
        return
      }

      print(outcomes ?? "Error printing outcomes.")
    
      completion(outcomes as? [HKQuantitySample])
    }
    
    healthStore.execute(question)
  }

Finally I need probably the most frequent coronary heart charge knowledge that’s obtainable. Ideally a bpm measurement each 5 – 10 seconds or much less. Is that this attainable if I’ve not explicitly saved this coronary heart charge knowledge to the well being retailer for a consumer earlier than attempting to entry it or does Apple retailer all of this info within the well being retailer whatever the circumstances?

Any assistance is significantly appreciated!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments