Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error when sending event: healthKit:ActiveEnergyBurned:setup:success with body: { }. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in RCTAppleHealthKit, even though it's inherited from RCTEventEmitter.' #166

Closed
shaheem-khanzada opened this issue Oct 14, 2021 · 15 comments
Assignees
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@shaheem-khanzada
Copy link

shaheem-khanzada commented Oct 14, 2021

2021-10-14 15:40:31.225818+0500 nikenft[2680:1606672] [HealthKit] Background observers will be added to the app
2021-10-14 15:40:31.228034+0500 nikenft[2680:1606672] [HealthKit] Background observers added to the app
2021-10-14 15:40:31.233119+0500 nikenft[2680:1606919] *** Assertion failure in -RCTEventEmitter sendEventWithName:body:, /Users/muhammadshaheem/Documents/Work/Projects/nikenft/node_modules/react-native/React/Modules/RCTEventEmitter.m:58
2021-10-14 15:40:31.233242+0500 nikenft[2680:1606918] [connection] nw_endpoint_handler_set_adaptive_read_handler [C2 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for read_timeout failed
2021-10-14 15:40:31.233335+0500 nikenft[2680:1606918] [connection] nw_endpoint_handler_set_adaptive_write_handler [C2 172.20.10.2:8081 ready socket-flow (satisfied (Path is satisfied), viable, interface: bridge100, ipv4, dns)] unregister notification for write_timeout failed
2021-10-14 15:40:31.234060+0500 nikenft[2680:1606919] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error when sending event: healthKit:ActiveEnergyBurned:setup:success with body: {
}. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in RCTAppleHealthKit, even though it's inherited from RCTEventEmitter.'
*** First throw call stack:
(0x1883f6708 0x19cf007a8 0x1882f83b8 0x18972181c 0x104dc1894 0x104c43374 0x10932c0b4 0x10932dde0 0x109335ef0 0x109336d48 0x109343a50 0x1d40667a4 0x1d406d74c)
libc++abi: terminating with uncaught exception of type NSException
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error when sending event: healthKit:ActiveEnergyBurned:setup:success with body: {
}. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in RCTAppleHealthKit, even though it's inherited from RCTEventEmitter.'

image

I am getting these issues when adding Background Observer Support

#import "AppDelegate.h"

...

/* Add the library import at the top of AppDelegate.m */
#import "RCTAppleHealthKit.h"

...

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self
                                            launchOptions:launchOptions];

  ...

  /* Add Background initializer for HealthKit  */
  [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge];

  ...

  return YES;
}
@shaheem-khanzada shaheem-khanzada added the bug Something isn't working label Oct 14, 2021
@moulie415
Copy link

@shaheem-khanzada latest version is broken for me as well, I'd recommend rolling back to 1.10.0 for the time being

@shaheem-khanzada
Copy link
Author

@moulie415 thanks 🙏

@shaheem-khanzada
Copy link
Author

@moulie415 one more thing can we use this for fitness tracking like start workout and start tracking

@moulie415
Copy link

@mnakai
Copy link

mnakai commented Dec 8, 2021

Probably facing the same issue.

my environments.
Xcode 13.1
iOS 14.8.1 (iPhone 6s)
RN 0.66.3
react-native-health 1.12.0, 1.11.0, 1.10.0

The app will close immediately after launching.

Exception NSException * "Error when sending event: healthKit:ActiveEnergyBurned:setup:success with body: {\n}. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in RCTAppleHealthKit, even though it's inherited from RCTEventEmitter." 0x0000000281bc1a10

Does anyone have "Background Observers" working?

@mnakai
Copy link

mnakai commented Dec 14, 2021

@moulie415 thanks 🙏

Did it work after downgrading?

Im facing the same issue on v1.10.0,v1.11.0,v1.12.0.

@camposer
Copy link

@moulie415 downgrading to 1.10.0 works. But when you try to get samples in the background listener, it always obtains empty. The console logs multiple times: "RNHealth: An error occured while trying to add sample from: com.apple.health." (similar to #177)

Any ideas?

My App.tx:

import React, {useState} from 'react';
import {
  NativeAppEventEmitter,
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  useColorScheme,
  View,
} from 'react-native';

import {
  Colors,
  Header,
} from 'react-native/Libraries/NewAppScreen';

import AppleHealthKit, {
  HealthValue,
  HealthKitPermissions,
  HealthInputOptions,
  HealthObserver,
} from 'react-native-health'

const Section: React.FC<{
  title: string;
}> = ({children, title}) => {
  const isDarkMode = useColorScheme() === 'dark';
  return (
    <View style={styles.sectionContainer}>
      <Text
        style={[
          styles.sectionTitle,
          {
            color: isDarkMode ? Colors.white : Colors.black,
          },
        ]}>
        {title}
      </Text>
      <Text
        style={[
          styles.sectionDescription,
          {
            color: isDarkMode ? Colors.light : Colors.dark,
          },
        ]}>
        {children}
      </Text>
    </View>
  );
};

const initHealthKit = () => {
  const permissions = {
    permissions: {
      read: [AppleHealthKit.Constants.Permissions.HeartRate]
    },
  } as HealthKitPermissions

  AppleHealthKit.initHealthKit(permissions, (error: string) => {
    if (error) {
      console.log('[ERROR] Cannot grant permissions!')
    }
    console.log('HealthKit initialized');
  });
};

const configureNativeAppEventEmitter = (setHeartRates: React.Dispatch<React.SetStateAction<HealthValue[]>>) => {
  NativeAppEventEmitter.addListener('healthKit:HeartRate:setup:success', () => {
    console.log('Native listener enabled');
  });

  NativeAppEventEmitter.addListener('healthKit:HeartRate:new', (data: any) => {
    console.log('************ Yaaaaaay', data);

    let options : HealthInputOptions = {
      startDate: new Date(2022, 0, 1).toISOString(),
      type: 'HeartRate' as HealthObserver
    };

    AppleHealthKit.getSamples(options, (err: Object, results: HealthValue[]) => {
      if (err) {
        console.error(err);
        return;
      }
      if (results == null) {
        console.log('Empty results');
        return;
      }
      const heartRates = results.slice(0, 4)
      console.log('HeartRates', heartRates);
      setHeartRates(heartRates)
    });

  });
}

const App = () => {
  const isDarkMode = useColorScheme() === 'dark';
  const [heartRates, setHeartRates] = useState<HealthValue[]>([])

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  initHealthKit();
  configureNativeAppEventEmitter(setHeartRates);

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}>
        <Header />
        <View
          style={{
            backgroundColor: isDarkMode ? Colors.black : Colors.white,
          }}>
          <Section title="Heart Rate">
            {JSON.stringify(heartRates)}
          </Section>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
};

export default App;

@bodrius
Copy link

bodrius commented Feb 9, 2022

same error

@JDMathew
Copy link

JDMathew commented Mar 9, 2022

@AnnyFigueira, I believe this is an issue with this commit (8d8cb16). It may only be an issue on M1.

@oyesaxena
Copy link

oyesaxena commented May 25, 2022

@AnnyFigueira, I believe this is an issue with this commit (8d8cb16). It may only be an issue on M1.

@JDMathew what do you suggest should be the fix for this ? I went back to version 1.10.0 but it didn't work out there as well.
I m migrating to version 0.68.0 of React native and that's when i hit this error. I was already using the library with 0.64.2 version of react-native and 1.12.0 version of React-native-health.

here is my error
Error when sending event: healthKit:ActiveEnergyBurned:setup:success with body: {\n}. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in RCTAppleHealthKit, even though it's inherited from RCTEventEmitter.

@oyesaxena
Copy link

@macelai can you please update on this ? Has been opened since a long time

@macelai
Copy link
Contributor

macelai commented May 25, 2022

@macelai can you please update on this ? Has been opened since a long time

@oyesaxena There is no one working actively on this project, we are open to PRs.

@devpascoe
Copy link

Hey folks. Still getting this, anyone found a work around yet? Rolled back to 1.10.0 for the time being.

@usharmaMobileDevTeam
Copy link

Facing same issue, downgraded on 1.10.0, didn't get fixed, Any other solutions?

@GGGava GGGava self-assigned this Jan 12, 2023
@GGGava GGGava added the duplicate This issue or pull request already exists label Jan 13, 2023
@GGGava
Copy link
Contributor

GGGava commented Jan 13, 2023

This is the same issue as #201. I will close this one as a duplicate to focus the discussion/updates on #201, as it's more active.

@GGGava GGGava closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests