Created
May 1, 2019 03:44
-
-
Save hungtruong/918839f7ba4a213c92817b387a6fd91f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) { | |
for type in collectedTypes { | |
guard let quantityType = type as? HKQuantityType else { | |
return | |
} | |
switch quantityType { | |
case HKQuantityType.quantityType(forIdentifier: .heartRate): | |
guard let statistics = workoutBuilder.statistics(for: quantityType), | |
let value = statistics.mostRecentQuantity()?.doubleValue(for: heartRateUnit) | |
else { | |
break | |
} | |
self.updateHeartRate(Int(value)) | |
default: | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment