Open zhang-bo-lilly opened 2 years ago
That behavior is correct. The outcomes you add into HealthKit are stored within your device’s HealthKit store, not inside of your app. CareKit reads those values from HealthKit and shows them along side the data it owns, but it doesn’t synchronize them.
This is a shortcoming that we’d like to address someday. @cbaker6 might be able to compensate for it within his plugin somehow, but ideally CareKit would do the book keeping.
@erik-apple, thank you for the reply. If you don't mind, I would like to double check my interpretation to make sure I get this correct.
I understand that the step count outcomes I added are stored within the device's HealthKit store and the app is simply reading from it. In fact, based on #569, I only ask for read permission of step count from the HealthKit with no intention to write back to it.
I set up breakpoints in all methods of the OCKHealthKitStore+Outcomes file and observe the breakpoint is only triggered in the fetchOutcomes
method after I add data to HealthKit store and prepare to go back to the view.
https://github.com/carekit-apple/CareKit/blob/a612482e4ba4f28d4c75129c0a9b70ca23098bd6/CareKitStore/CareKitStore/HealthKit/OCKHealthKitStore%2BOutcomes.swift#L158
In the debugger, I noticed that isOwnedByApp
is always false
. I guess this means even the addOutcomes
method in this file is called somewhere (and I am not sure whether this method is ever called), the following line leaves samples
empty
https://github.com/carekit-apple/CareKit/blob/a612482e4ba4f28d4c75129c0a9b70ca23098bd6/CareKitStore/CareKitStore/HealthKit/OCKHealthKitStore%2BOutcomes.swift#L65
As a result, even if I want to save something (which I don't), there is nothing to save at this line.
https://github.com/carekit-apple/CareKit/blob/a612482e4ba4f28d4c75129c0a9b70ca23098bd6/CareKitStore/CareKitStore/HealthKit/OCKHealthKitStore%2BOutcomes.swift#L85
It seems to me the outcome of the HealthKitTask is properly displayed to the UI when needed, but not saved to the OCKStore. Is this interpretation correct?
For my case, if I want to know the outcome of the OCKHealthKitTask and sync it to a remote server, it seems that I need to execute a query past the end of the underlying schedule (e.g., execute the query after 16:05). Is this the correct way to handle this?
Lastly, I notice that both OCKHealthKitPassthroughStore
and OCKHealthKitProxy
call HKHealthStore()
. The developer documentation, however, states one need only a single HealthKit store per app. May I know the reasons why two are created here? Thanks.
https://github.com/carekit-apple/CareKit/blob/a612482e4ba4f28d4c75129c0a9b70ca23098bd6/CareKitStore/CareKitStore/HealthKit/OCKHealthKitPassthroughStore.swift#L56
https://github.com/carekit-apple/CareKit/blob/a612482e4ba4f28d4c75129c0a9b70ca23098bd6/CareKitStore/CareKitStore/HealthKit/OCKHealthKitProxy.swift#L35
I am working on a CareKit app where I use ParseCareKit developed by @cbaker6 for remote synchronization and his parse-hipaa for the server. Within the app, I defined three tasks: an onboarding task similar to the demo shown in WWDC, a daily stretch task, and a walking task. The onboarding and stretch tasks are created using
OCKTask
and the walking task is created as anOCKHealthKitTask
. Here are the code snippets related to the creation and display of the HealthKit task.Above is a screenshot of the app in the simulator. In the simulator, I manually add step data to the Health app and can observe the cumulative values being updated at the same time.
Back to the server side. On the Parse dashboard, I am able to observe (1) all three tasks are successfully added to the data store and sync'ed to the server. (2) The outcomes of the
OCKTask
s are also saved to the data store after completion and sync'ed to the server.However, I am unable to observe any outcome related to the
HealthKitTask
ever sync'ed to the remote, even past the schedule time (16:05 in the screenshot). Assuming ParseCareKit correctly synchronizes data from the device to the server, I am not sure if the outcome of this HealthKitTask is saved anywhere to the data store on the device. Am I missing something here?