Description:
When attempting to read data from HKQuantityTypeIdentifierHeadphoneAudioExposure, the app crashes with the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to convert incompatible units: dBASPL, Pa'
Cause:
The code currently uses .pascal() as the unit for reading headphoneAudioExposure, which is not compatible with this quantity type.
According to Apple’s HealthKit documentation, HKQuantityTypeIdentifierHeadphoneAudioExposure expects the unit to be:
HKUnit.decibelAWeightedSoundPressureLevel()
Proposed Fix:
`case .environmentalAudioExposure,
.headphoneAudioExposure:
if #available(iOS 13.0, *) {
return quantity(unit: HKUnit.decibelAWeightedSoundPressureLevel())
} else {
throw HealthKitError.notAvailable(
"\(type) is not available for the current iOS"
)
}`
Let me know if you’d like me to submit a PR for this. Thanks!