I want to be able to tell if the user has allowed my app to read their health data. I found some code that seems to be doing just that, however, whenever I call the function, it always prints "Denied", instead of "Authorized", even though I am allowing it on my test device. Here's my code:
func checkAuthorization() {
let authorizationStatus = healthStore.authorizationStatus(for: HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.sleepAnalysis)!)
if authorizationStatus == HKAuthorizationStatus.sharingAuthorized {
print("Authorized")
} else if authorizationStatus == HKAuthorizationStatus.sharingDenied {
print("Denied")
} else {
print("Unknown")
}
}