Skip to content

headphoneAudioExposure uses incorrect unit pascal, should be decibelAWeightedSoundPressureLevel #29

Description

@zrj1884

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions