react-native-health
react-native-health copied to clipboard
AppleHealthKit.saveWorkout() doesn't save a workout
Describe the bug Hello, Looks like AppleHealthKit.saveWorkout() doesn't save a workout
To Reproduce Steps to reproduce the behavior:
I do in this way
let options = {
type: 'AmericanFootball', // See HealthActivity Enum
startDate: new Date(2021, 5, 12, 12, 0, 0).toISOString(),
endDate: new Date(2021, 5, 12, 13, 30, 0).toISOString(),
energyBurned: 50, // In Energy burned unit
distance: 50, // In Distance unit
}
AppleHealthKit.saveWorkout(
(options),
(err, results) => {
if (err) {
console.log('error saving workout to Healthkit: ', err)
return
}
// workout successfully saved
console.log(results, 'workout successfully saved')
},
)
The interestiong thing is thay I do receive console.log result 'workout successfully saved' with the UUIDString. Also, what about saveWeight method, it is working and I do saved data in apple health
All necessary permissions are granted in this way:
const permissions = {
permissions: {
read: [AppleHealthKit.Constants.Permissions.HeartRate],
write: [
AppleHealthKit.Constants.Permissions.Steps,
AppleHealthKit.Constants.Permissions.Weight,
AppleHealthKit.Constants.Permissions.Workout,
],
},
}
AppleHealthKit.initHealthKit(permissions, (error) => {
/* Called after we receive a response from the system */
AppleHealthKit.getAuthStatus(permissions, (err, results) => {
console.log(err, results, 'AUTH STATUS')
})
if (error) {
console.log('[ERROR] Cannot grant permissions!')
}
})
Expected behavior I do expect, that this activity will appear in apple health app
Screenshots
Screenshot
Smartphone:
- Device: iPhone 8 simulator, iPhone 11 real
- OS: iOS 14.4
- Version "react-native-health": "^1.7.2"
The interestiong thing is thay I do receive console.log result 'workout successfully saved' with the UUIDString.
Can you go to the Health App > Your profile (top right, your profile picture) > under the Privacy section tap on "Apps", find the app you're developing and tap on it > then tap on "Data" and see if there are any activities written there. You should see your data there.
I do expect, that this activity will appear in apple health app
Your code puts the workout in the future (5 is June in JS), that's why you don't see it Health > Activity. Once you put in a date in the past, it will appear in Health > Activity > Workouts.
Edit: This is not a bug so I think we should remove the bug
label. saveWorkout()
still doesn't save all data passed to it, but there's an open issue about it: #92
The interestiong thing is thay I do receive console.log result 'workout successfully saved' with the UUIDString.
Can you go to the Health App > Your profile (top right, your profile picture) > under the Privacy section tap on "Apps", find the app you're developing and tap on it > then tap on "Data" and see if there are any activities written there. You should see your data there.
I do expect, that this activity will appear in apple health app
Your code puts the workout in the future (5 is June in JS), that's why you don't see it Health > Activity. Once you put in a date in the past, it will appear in Health > Activity > Workouts.
Edit: This is not a bug so I think we should remove the
bug
label.saveWorkout()
still doesn't save all data passed to it, but there's an open issue about it: #92
Thank your for the reply!
That's the weird, but I do not see my app in apps list, but I've granted all the permissions on a first start of the app.
Screenshot

Can anyone help?
@tagirahmad I am having problems reproducing this issue. Can you create a repository reproducing your problem?
@tagirahmad I am having problems reproducing this issue. Can you create a repository reproducing your problem?
I can't show you my production code. But I've created a test repo, here is the same problem
https://github.com/tagirahmad/healthapp-sample
Hey @tagirahmad!
Thanks for the rich context regarding the issue
I've been trying to reproduce from your sample repository, but as @fakeheal mentioned, I'm seeing the samples being saved in Apple Health (screenshots attached).
One possibility is that you are passing the includeManuallyAdded
as false
when requesting the information in your app. Could you just check that?
I will do additional tests in the following days to replicate the issue and let you know if I find anything
Hey @tagirahmad!
Thanks for the rich context regarding the issue
I've been trying to reproduce from your sample repository, but as @fakeheal mentioned, I'm seeing the samples being saved in Apple Health (screenshots attached).
One possibility is that you are passing the
includeManuallyAdded
asfalse
when requesting the information in your app. Could you just check that?I will do additional tests in the following days to replicate the issue and let you know if I find anything
Hi! Thank you for the reply and desire to help with my question.
In my code in both repos sample and production there is no any includeManuallyAdded.
How did you get that result with my healthapp-sample? I still don't have any updates in apple health app.
In terminal, I do have success messages as
6E8D2EC6-9694-41E5-A22F-0AC7D05A4C30 workout successfully saved
Maybe I do run my project in wrong way or anything else? Any permissions or lack of something in xcode project, I do not know really.
Can anyone help?
Hey, checked again and saveWorkout
seems to be working fine, although I found an issue when getting the saved workout with getSamples
.
@tagirahmad's code adds a workout with no metadata
(which is ok and it appears normally in Health), but getSamples
fails to fetch a workout with no metadata
, returning an empty array.
As this is an old issue and it's not clear if this is the exact case, I will fix the mentioned bug and close this issue. Please let me know if the issue persists.
Fix released in v.1.13.6