HealthKit.subscribeToChanges does not work with RN New Architecture enabled
https://github.com/KesoGizmoYoshi/rn-healthkit-test
I am unable to get subscribeToChanges to work on a project running with RN New Architecture enabled. The same code works perfectly when running on a prebuilt version with newArchEnabled set to false. When newArchEnabled is set to false, the console log successfully triggers when a new sample exists. However, when newArchEnabled is set to true, nothing happens, and the subscription does not seem to work.
Interesting. The example expo app is using the new architecture - but it doesn't really test the background functionality. We haven't upgraded to the new architecture in our own apps yet.
Are other background features working as expected with the new architecture enabled?
I did also try useSubscribeToChanges, but with no success with new architecture.
@KesoGizmoYoshi That makes sense since useSubscribeWithChanges uses subscribeToChanges under the hood.
I see! Anything else you want me to test?
Do you see anything in the device logs that might give a hint on what might be going on?
Also version of React Native and Expo if applicable would be helpful! :) I'll probably dig deeper into this when we have time to test out the new architecture ourselves 👍
Sorry for a late response, but I have only tested on expo 51.0.32 and react-native 0.75.2, hopefully I can test soon with expo 52. newArchEnabled: true https://gist.github.com/KesoGizmoYoshi/c796de82f5f1a2b6b1fc714c28485bda
newArchEnabled: false https://gist.github.com/KesoGizmoYoshi/2b3629a026c726b8d91d70ce9eb841e4
I tried using subscribeToChange method as well. But isn't working on my end. Any simple example on how to get the data updates in background would be helpful and appreciated. My project details - "react-native": "0.74.5", "expo": "^51.0.38" "@kingstinct/react-native-healthkit": "^8.2.0",
Here is sample code what I'm tried.
useEffect(() => {
let unsubscribe :any;
if (hasRequestedAuthorization) {
unsubscribe = HealthKit.subscribeToChanges(HKQuantityTypeIdentifier.heartRate, () => {
const mostRecentData = await queryQuantitySamples(HKQuantityTypeIdentifier.heartRate, {
limit: 1,
});
console.log("most recent data is", mostRecentData);
});
}
return () => unsubscribe;
}, [hasRequestedAuthorization]);
I'm calling queryQuantitySample in subscribeToChanges to get the most recent data. but I'm not sure is this way to get data. The subscribeToChange method itself was supposed to send latest data. Question: I want to know what is best practice in order to get the data continuously in background from apple health only if there's an event update. I find out that many people has issue fetching background data and couldn't find any helpful resource. My requirement is to get updated data each time that is updated by apple watch or health app. Any hints on how to do it ?
Could anyone make it work?
Sorry for a late response, but I have only tested on expo 51.0.32 and react-native 0.75.2, hopefully I can test soon with expo 52. newArchEnabled: true https://gist.github.com/KesoGizmoYoshi/c796de82f5f1a2b6b1fc714c28485bda
newArchEnabled: false https://gist.github.com/KesoGizmoYoshi/2b3629a026c726b8d91d70ce9eb841e4
It looks to me dataUpdatedInDatabase is called in both cases - if that's the indication of subscribeToChanges callback being called? Or am I misinterpreting these logs?
Sorry for a late response, but I have only tested on expo 51.0.32 and react-native 0.75.2, hopefully I can test soon with expo 52. newArchEnabled: true https://gist.github.com/KesoGizmoYoshi/c796de82f5f1a2b6b1fc714c28485bda newArchEnabled: false https://gist.github.com/KesoGizmoYoshi/2b3629a026c726b8d91d70ce9eb841e4
It looks to me
dataUpdatedInDatabaseis called in both cases - if that's the indication of subscribeToChanges callback being called? Or am I misinterpreting these logs?
Could you confirm it worked when the app was completely closed or just when it's backgrounded?
I am new arch and also cannot get it to work at all
Sorry for a late response, but I have only tested on expo 51.0.32 and react-native 0.75.2, hopefully I can test soon with expo 52. newArchEnabled: true https://gist.github.com/KesoGizmoYoshi/c796de82f5f1a2b6b1fc714c28485bda newArchEnabled: false https://gist.github.com/KesoGizmoYoshi/2b3629a026c726b8d91d70ce9eb841e4
It looks to me
dataUpdatedInDatabaseis called in both cases - if that's the indication of subscribeToChanges callback being called? Or am I misinterpreting these logs?
Yeah, i think you are correct about the callback being called. :)
Sorry for a late response, but I have only tested on expo 51.0.32 and react-native 0.75.2, hopefully I can test soon with expo 52. newArchEnabled: true https://gist.github.com/KesoGizmoYoshi/c796de82f5f1a2b6b1fc714c28485bda newArchEnabled: false https://gist.github.com/KesoGizmoYoshi/2b3629a026c726b8d91d70ce9eb841e4
It looks to me
dataUpdatedInDatabaseis called in both cases - if that's the indication of subscribeToChanges callback being called? Or am I misinterpreting these logs?Could you confirm it worked when the app was completely closed or just when it's backgrounded?
I dont really remember.
Any updates on that?
@robertherber Any update on this? We're really struggling with this issue. Can you please tell us the next steps to resolve this issue?
Currently, there are no sync operations possible from our watch app to our react-native app
We're using expo: 52.0.38 sdk and @kingstinct/react-native-healthkit 8.2.0
@zain148 Hello, I struggling with this issue too. But, I wanna know, Did the background function work fine before?