react-native-health: App crashing when configuring background observer

Describe the bug Adding the line [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge]; causes the app to crash when opening To Reproduce Steps to reproduce the behavior:

  1. Go to ‘AppDelegate.m’ and implement the changes listed here: https://github.com/agencyenterprise/react-native-health/blob/HEAD/docs/background.md

Expected behavior App should report health data in the background

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: iPhone 11 Pro Max
  • OS: iOS14.8.1
  • Version 1.12.0

Additional context App crashes when specifically adding: [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge]; AppDelegate.txt

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 12
  • Comments: 31 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Same here, any solutions?

Hi @GGGava, thanks for putting time into this issue so far, I am @JDMathew’s co-worker.

I have run the project entirely using rosetta and have had the same issue.

I also had the issue on my Intel Mac and my M1 mac, but on the intel mac, I was able to run the project successfully some of the time, but after a full clear, a fresh pull of the repo and a rebuild it then presented with the same issue.

It fails for me on a sim as well as building directly to a device. iPhone 8 in my example.

Thanks again for your time on this.

Hello, we currently don’t have an active developer in this project, but I will try to investigate this in my spare time, hopefully this week. Until then, if you guys find a solution for that, a PR would be most welcome!

@GGGava, sorry for the delay in getting the repo up. I am unable to share my main project but I created a fresh RN project and setup react-native-health in it with the same issue. Here is the repo. Hopefully you can reproduce.

While I have had this issue on M1 I have colleagues who have it on intel based macs. I also have colleagues who don’t have the issue on M1.

I am using nvm I’m not sure if this is contributing but I have experienced weirdness in the past with the way node is run on nvm.

To answer your questions 1- Does it happen at all on simulator or just on iPhones? I don’t have an iphone to build to so the issue is happening for me on sim builds 2- Only adding [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge];to the delegate is enough or is there something else in you App.tsx? Adding [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge]; is enough. Nothing else happening in my example app. 3- Building the app with rosetta changes anything? I haven’t tested running xcode through rosetta. I is this how you are running it?