Skip to content

getWater() crashes app when HealthKit returns nil — should handle missing values safely #416

@Georg7

Description

@Georg7

Describe the bug
Calling AppleHealthKit.getWater() crashes the app on when HealthKit returns missing or undefined values (e.g. no water data). This happens in native code due to a nil value being inserted into an NSDictionary, which causes a fatal SIGABRT. The crash cannot be caught on the JS side, even with try/catch.

To Reproduce
Steps to reproduce the behavior:

  1. Ensure there are no water intake entries for the current day in Apple Health
  2. Call AppleHealthKit.getWater({ date: new Date() }, callback) from React Native
  3. Observe native crash before callback is triggered

Expected behavior
The native module should handle missing data gracefully:

  • Return null or a safe fallback in the response
  • Or reject with an error via the callback. It should not crash the entire app.

Screenshots
N/A, but crash log excerpt:

*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]

Thread 14 Crashed:
4   0x204987ff0 __56-[RCTAppleHealthKit getWater:callback:]_block_invoke (RCTAppleHealthKit+Methods_Dietary.m:557)

Smartphone (please complete the following information):

  • Device: iPhone 14
  • OS: iOS 18.5 (22F76)
  • Version: 1.18.0

Additional context
Looking at the native implementation of getWater, it appears sumQuantity or unit can be nil, and are inserted into an NSDictionary without nil checking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions