react-native-health: Fatal Exception: NSInvalidArgumentException when retrieving health data
Thanks for creating this library.
Describe the bug After migrating an app from rn-apple-healthkit to react-native-health there have been a large number of crashes reported in Crashlytics. The crash seems to occur when health data is received. However I have been unable to reproduce this error myself on an iPhone simulator or a physical device.
This is the error:
Fatal Exception: NSInvalidArgumentException ***[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]
Which seems to happen inside the completionHandler
in the method fetchSumOfSamplesOnDayForType
. This method is called from many other methods that retrieve various types of health data such as getStepCountOnDay
.
Where one of these values in *response
is nil, which due to the if-statement should be startDate or endDate. And buildISO8601StringFromDate
can return nil if there is an error.
Inside the completionHandler:
if (!value && value != 0) {
callback(@[RCTJSErrorFromNSError(error)]);
return;
}
NSDictionary *response = @{
@"value" : @(value),
@"startDate" : [RCTAppleHealthKit buildISO8601StringFromDate:startDate],
@"endDate" : [RCTAppleHealthKit buildISO8601StringFromDate:endDate],
};
callback(@[[NSNull null], response]);
Do you have an idea what might cause this error?
These are the permissions that I use:
const appleHealthKitOptions = {
permissions: {
read: [
AppleHealthKit.Constants.Permissions.StepCount,
AppleHealthKit.Constants.Permissions.SleepAnalysis,
AppleHealthKit.Constants.Permissions.HeartRate,
AppleHealthKit.Constants.Permissions.DistanceCycling
],
write: []
}
};
And these AppleHealthKit methods:
AppleHealthKit.getDailyStepCountSamples
AppleHealthKit.getDailyDistanceCyclingSamples
AppleHealthKit.getSleepSamples
AppleHealthKit.getHeartRateSamples
To Reproduce Unfortunately I cannot reproduce it myself.
Smartphone (please complete the following information):
- Device: It happens on many different types of iPhones
- OS: Both iOS 13 and 14
- Version 1.7.0
Thanks a lot.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 23 (2 by maintainers)
Hey guys, I plan to take a deep look into this crash in a few days. If you have any additional information it would be very welcome, thanks
I’m having this issue, did anybody figure it out?