You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this case, I initialize this data from a useEffect hook which sets a useState hook value in a constant via setWearablesPermissionStatus(true) (or false in the case of error).
From my context, I query the most recent record of heartRate from my database and set either [] if the user doesn't have any data, or the data is set as the most recent item.
request AppleHealthKit like this:
useEffect(() => {
// get updated heart rate data from pertinent wearables and write to userheartrate table
const getUpdatedHeartRateData = async () => {
if (recentHeartRateItem && Platform.OS === "ios") {
if (recentHeartRateItem.length === 0) {
let options = {
startDate: moment().startOf('day').toISOString(),
endDate: moment().toISOString(),
}
AppleHealthKit.getHeartRateSamples(options, (err, results) => {
if (err) {
console.log('error getting healthkit heart rate data: ', err);
return;
}
console.log('healthkit heart rate results: ', results, results.length)
setNewHeartRateRecords(results)
})
}
if (recentHeartRateItem.length > 0) {
let options = {
startDate: moment(recentHeartRateItem[0].HeartRateEndDate).toISOString(),
endDate: moment().toISOString(),
}
AppleHealthKit.getHeartRateSamples(options, (err, results) => {
if (err) {
console.log('error getting healthkit heart rate data: ', err);
return;
}
console.log('healthkit heart rate results: ', results, results.length)
setNewHeartRateRecords(results)
})
}
}
}
getUpdatedHeartRateData();
}, [recentHeartRateItem])
Getting this response: healthkit heart rate results: [] 0
Expected behavior AppleHealthKit.getHeartRateSamples should return an array of the data within the time frame as opposed to an empty array.
Screenshots
Screenshots from Apple Health showing existing data and the existence of heart rate values:
Smartphone (please complete the following information):
Device: iPhone 13 mini
OS: iOS16.1.1
Version ?
Additional context
I have a getSleepSamples query which seems to work fine with the same setup in my code. However, getHeartRateSamples and getSamples does not work as expected. Maybe it's as simple as a permission issue? Do I need more permissions for this data?
The text was updated successfully, but these errors were encountered:
Update: After changing my query startDate to the meginning of the month, I retrieve the heart rate data. Unsure as to why the start of the day does not return anything.
Describe the bug
AppleHealthKit.getHeartRateSamples
is returning an empty array[]
regardless of existing data and permissions.To Reproduce
Steps to reproduce the behavior:
In this case, I initialize this data from a
useEffect
hook which sets auseState
hook value in a constant viasetWearablesPermissionStatus(true)
(or false in the case of error).From my context, I query the most recent record of heartRate from my database and set either
[]
if the user doesn't have any data, or the data is set as the most recent item.request
AppleHealthKit
like this:healthkit heart rate results: [] 0
Expected behavior
AppleHealthKit.getHeartRateSamples
should return an array of the data within the time frame as opposed to an empty array.Screenshots
Screenshots from Apple Health showing existing data and the existence of heart rate values:
Smartphone (please complete the following information):
Additional context
I have a
getSleepSamples
query which seems to work fine with the same setup in my code. However,getHeartRateSamples
andgetSamples
does not work as expected. Maybe it's as simple as a permission issue? Do I need more permissions for this data?The text was updated successfully, but these errors were encountered: