I am creating an iWatch app which reads HeartRate data which I then use to plot some graphs. There are 2 buttons in the app, one to pause the workout session and other to resume the workout session. On click of Pause button, I am calling pauseWorkoutSession
method of healthStore:
healthStore.pauseWorkoutSession(workoutSession!)
OnClick of Resume Button, I am calling resumeWorkoutSession
method of healthStore:
healthStore.resumeWorkoutSession(workoutSession!)
To get HeartRate data, I am running the following code:
let quantityType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)!
let datePredicate = HKQuery.predicateForSamplesWithStartDate(instanceDel.workoutSessionStartDate, endDate: nil, options: .StrictStartDate)
let updateHandler: (HKAnchoredObjectQuery,[HKSample]?,[HKDeletedObject]?,HKQueryAnchor?,
NSError?)-> Void = {query, samples, deleteObjects, newAnchor, error in
if !self.instanceDel.workoutPaused {
//do something
}
}
heartRateQuery = HKAnchoredObjectQuery(type: quantityType, predicate: datePredicate, anchor: nil, limit: Int(HKObjectQueryNoLimit) , resultsHandler: updateHandler)
heartRateQuery!.updateHandler = updateHandler
instanceDel.healthStore.executeQuery(heartRateQuery!)
The problem I am facing is that update handler is continuously called and new heart rate values are are continuously added to samples array even when workout is paused. What does pauseWorkoutSession
exactly does? Isn'
t it suppose to pause the workout session so that new new heart rate reading come?