guard let quantityType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate) else { return nil } let heartRateQuery = HKAnchoredObjectQuery(type: quantityType, predicate: predicate, anchor: anchor, Int(HKObjectQueryNoLimit)) { (query, sampleObjects, deletedObjects, newAnchor, error) -> Void in guard let newAnchor = newAnchor else {return} self.anchor = newAnchor self.updateHeartRate(sampleObjects) } heartRateQuery.updateHandler = {(query, samples, deleteObjects, newAnchor, error) -> Void in self.anchor = newAnchor! self.updateHeartRate(samples) } return heartRateQuery } let heartRateQuery = This will make the watch start HKAnchoredObjectQuery(type: quantityType, measuring the Heart rate predicate: predicate, anchor: anchor, Int(HKObjectQueryNoLimit)) { (query, sampleObjects, deletedObjects, newAnchor, error) -> Void in let newAnchor = newAnchor else {return} self.anchor = newAnchor self.updateHeartRate(sampleObjects) This will save the value of the heart heartRateQuery.updateHandler = {(query, samples, deleteObjects, newAnchor, error) -> Void in rate with the value the watch self.anchor = newAnchor! measures it. self.updateHeartRate(samples) This function updateHeartRate will if the heart rate crosses certain level. func updateHeartRate(samples: [HKSample]?) {
guard let quantityType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate) else { return nil } let heartRateQuery = HKAnchoredObjectQuery(type: quantityType, predicate: predicate, anchor: anchor, Int(HKObjectQueryNoLimit)) { (query, sampleObjects, deletedObjects, newAnchor, error) -> Void in guard let newAnchor = newAnchor else {return} self.anchor = newAnchor self.updateHeartRate(sampleObjects) } heartRateQuery.updateHandler = {(query, samples, deleteObjects, newAnchor, error) -> Void in self.anchor = newAnchor! self.updateHeartRate(samples) } return heartRateQuery } let heartRateQuery = HKAnchoredObjectQuery(type: quantityType, predicate: predicate, anchor: anchor, Int(HKObjectQueryNoLimit)) { (query, sampleObjects, deletedObjects, newAnchor, error) -> Void in let newAnchor = newAnchor else {return} self.anchor = newAnchor self.updateHeartRate(sampleObjects) This will make the watch start measuring the Heart rate heartRateQuery.updateHandler = {(query, samples, deleteObjects, newAnchor, error) -> Void in self.anchor = newAnchor! self.updateHeartRate(samples) This will save the value of the heart rate with the value the watch measures it. This function updateHeartRate will if the heart rate crosses certain level. func updateHeartRate(samples: [HKSample]?) {
ThesisV5.docx