Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HealthKit data inaccessible in background

I want to pull HealthStore data in the background using background fetch but I keep getting an error: Error Domain=com.apple.healthkit Code=6 "Protected health data is inaccessible" UserInfo=0x17026fdc0 {NSLocalizedDescription=Protected health data is inaccessible}.

Apple states:

Because the HealthKit store is encrypted, your app cannot read data from the store when the phone is locked. This means your app may not be able to access the store when it is launched in the background.

Any workaround to access data in the background? Is the HKObserverQuery the only way to get data in the background?

like image 238
efremidze Avatar asked May 20 '15 21:05

efremidze


People also ask

How do I enable HealthKit on my iPhone?

HealthKit can only be used for iOS phones. If you are interested in HealthKit please go to Settings and select Enable HealthKit. On the next page you'll be asked to allow GeneralHealth to access your health data. HealthKit will be enabled when you tap 'Enable Healthkit' at the bottom of the screen.

Is Apple health the same as HealthKit?

HealthKit is the developer framework behind it that allows apps to work with Apple Health and each other. If you're confused about how the Apple Health app works, what type of information you need to get the most out of it, and which apps are compatible, keep reading.

Where is HealthKit data stored?

To quote: This data is stored in Data Protection class Protected Unless Open. Access to the data is relinquished 10 minutes after device locks, and data becomes accessible the next time user enters their passcode or uses Touch ID or Face ID to unlock the device.

What is HealthKit on Apple Watch?

HealthKit provides a central repository for health and fitness data on iPhone and Apple Watch. With the user's permission, apps communicate with the HealthKit store to access and share this data.


1 Answers

As stated in the documentation you quoted there's no way to access HealthKit data while the phone is locked. However, you can access the data if the phone is unlocked and your app is in the background. So if background fetch happens while the phone is unlocked you will be able to access the data.

like image 143
ospr Avatar answered Oct 09 '22 23:10

ospr