Post

Replies

Boosts

Views

Activity

Getting sharingDenied when trying to check for access to activitySummaryType
So, I've wrote the following code; let status = healthStore.authorizationStatus(for: .activitySummaryType()) switch status { case .notDetermined: return false case .sharingDenied: return false case .sharingAuthorized: return true @unknown default: return false } And it is hitting the .sharingDenied case. This doesn't make sense as on my phone I have allowed read access (there's no sharing option per the documentation). As soon as I change out to let's say; let checkHkQuantityTypeAuthorization = HKObjectType.quantityType(forIdentifier: .stepCount) I am able to hit the case .sharingAuthorized case. What doesn't make sense is that even though it fails this check, if I just go ahead and query for the Activity Summary for the ring data via; let predicate = HKQuery.predicate(forActivitySummariesBetweenStart: startDateComponents, end: endDateComponents) let query = HKActivitySummaryQuery(predicate: predicate) { (query, summaries, error) { ... } It works just fine and I can pull the Activity data without changing any permissions in the Privacy settings of my iPhone or iPad. So, I know I can pull the data just fine, and that everything is set correctly for the Entitlements. I just want to make sure that the user has actually allowed me to before I try to pull the data. Additional Notes: The REALLY weird thing is that that when I try to pull the .stepCount, is that it will hit the .sharingDenied case if I only have the user do READ access. So, I've had to make my app also request for WRITE (share) access. Like this doesn't make any sense for me to request both READ and WRITE access to step count when my app only needs read access (like Activity Summary data). This seems like a bug in my opinion as I don't see anything related in the documentation in regards to this on the If this is how this is supposed to work given the discussion on the documentation; To help prevent possible leaks of sensitive health information, your app cannot determine whether or not a user has granted permission to read data. If you are not given permission, it simply appears as if there is no data of the requested type in the HealthKit store. If your app is given share permission but not read permission, you see only the data that your app has written to the store. Data from other sources remains hidden. Source: https://developer.apple.com/documentation/healthkit/hkhealthstore/1614154-authorizationstatus Then that is completely confusing. I want to check if I have permissions to read this data otherwise why bother trying to read the data or try to present anything to the user except that they need to allow access to me reading this data. Apple says that you should only request to relevant Health data when you need it. So this check is worthless if I am trying to check before I do the query because the UI wants to display data in regard to activity data. Honestly, this is really confusing if all this falls into the discussion item on the documentation and Apple needs to do better. EDIT: Further reading the very top of the method definition yields; Returns the app’s authorization status for sharing the specified data type. Like why Apple? I want to know if I can READ the type so I can tell the user to allow me access or not. This is frustrating.
0
1
618
Jul ’23