1

I'm using the following Swift code.

let lowHREventType = HKObjectType.categoryType(forIdentifier: .lowHeartRateEvent)
let lowHREventQuery = HKSampleQuery(sampleType: lowHREventType, predicate: nil, limit: 30, sortDescriptors: [sortByTime]) { (query, tmpResult, error) -> Void in
            
            if error != nil {
                
                // Handle the error in your app gracefully
                return
                
            }
            
            if let result = tmpResult {
                
                for item in result {
                    if let sample = item as? HKCategorySample {
                        print("Healthkit Low: \(sample.startDate) \(sample.endDate) - value: \(sample.value)")
                    }
                }
            }
        }

I get no result from the query. Please advise me on how to resolve this issue.

  • You define the query here but you do not start it. Do you have an instance of HKHealthStore to execute the query? I copied your code and it works fine for me. – john elemans Nov 24 '20 at 23:34
  • but I can't generate an alert from the apple watch. I also set high = 100 and low = 50 in the watch app. can you guide me on how to generate an alert so I check first in the health app – Mihir Pipermitwala Nov 25 '20 at 12:49
  • post a new question. show some code. maybe you need to start with simpler problems till you see how the code works. – john elemans Nov 25 '20 at 17:05
  • No @johnelemans, I need just first to see high or low heart rate notifications in the Apple Health app. after that this code works for fetch notification via health kit. I need to know how high and low heart notification to the Apple Health app. and how I produce alert – Mihir Pipermitwala Nov 26 '20 at 05:29

0 Answers0