Hi guys,
We have an app that consumes data from Apple HealthKit. We use an HKObserverQuery to monitor changes in HealthKit data, and occasionally use regular HKSampleQuery requests when the app is in the foreground.
Over the past few weeks, we’ve been encountering a significant number of errors when requesting additional HealthKit permissions (beyond what the user has already granted). The error message we’re seeing is:
The operation couldn't be completed. (_UIViewServiceInterfaceErrorDomain error 2.)
When this error occurs, all previously granted HealthKit permissions are automatically revoked, which is highly disruptive.
We have a few questions and would greatly appreciate any insights or explanations regarding this behavior:
Could this error occur if a permission request is triggered right as the app moves to the background? Why would previously granted permissions be revoked automatically after this error? If this is due to some internal behavior in iOS (e.g., a system-level protection or timeout), is there any known workaround or best practice to prevent this from happening?
Thanks in advance for your help!