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:
- 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
Same here, any solutions?
Additional exception info
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.
See also https://github.com/agencyenterprise/react-native-health/issues/166
Same issue
@GGGava, is it possible to get anyone from @agencyenterprise to look into this. Issue #116 has been open since October and it is essentially the same underlying problem due to inheritance from RCTEventEmitter. This may only be a problem on M1. I am running the latest react-native version 0.67.3 and have tested this on a fresh project with the same issue. I would be happy to expose that repo if you are unable to reproduce.
Same issue. The app crash when opening. I'm on M1 mac
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!
Hello guys, I was not able to reproduce this issue in the libs example app. I am on a M1 Mac and running on simulator. Maybe you can help me:
1- Does it happen at all on simulator or just on iPhones?
2- Only adding [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge];to the delegate is enough or is there something else in you App.tsx?
3- Building the app with rosetta changes anything?
Please share any other information that you may find useful.
@JDMathew if you could share your repo with instructions to run it would be awesome :D
@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?
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, sorry for the delay.
@JDMathew thank you for your repo, I could easily reproduce the issue. It seems that the react/react-native version on Package.json file was the reason that this issue was not happening on the example app.
"dependencies": {
- "react": "16.13.1",
- "react-native": "0.63.4",
+ "react": "17.0.2",
+ "react-native": "^0.67.3",
By changing this I was able to reproduce it. Not sure what is going on yet, but if downgrading is viable to you this may be a temporary fix to the issue. I will try to find a solution now :)
Hi @GGGava, ah that is interesting. Unfortunately we can't downgrade react native at this point in time. We have downgraded react-native-health to 1.10.0 as it isn't broken in that version. We would be happy to test on the next version once a fix is released.
We are also currently experiencing a number of stability issues where data stops syncing even though health permissions are granted.
Hey @JDMathew could you help me testing c1f4dd1e2c65a2906110c07e23dbe0d527fbbb79? This seems to have solved the crash but I was not able to test background deliveries in the example app. If you are unable, I can give a second shot next week.
Hi @GGGava thank you so much for the work in this issue. I can attest that c1f4dd1 does not work in reestablishing the background deliveries. I think it is more related to https://github.com/agencyenterprise/react-native-health/issues/144 and https://github.com/agencyenterprise/react-native-health/issues/166 but it was worth testing. Our environment:
- React Native 0.64.2
- React 17.0.1
- Intel Mac
- React Native Health c1f4dd1
Note: neither vanila 1.12.0 nor c1f4dd1 crashes our app.
Do you have any ideas of what could be causing it (background delivery not firing)? I'm willing to help researching into it
@gabrieltnishimura Not sure if you are aware of it or not, but there are some minimum update frequencies depending on the type of data. Have a look at this SO thread: https://stackoverflow.com/a/35073904/1439994
They also have an example app which you can play around with here. If possible, you could transfer all dependancies/files from your existing app to this one and work up from there -- this is what worked for me.
@GGGava hi. It seems like background observers configuration still causes crash with the latest react native version. Do you plan to merge that commit, at least to prevent the crash?
Hey @JDMathew could you help me testing c1f4dd1? This seems to have solved the crash but I was not able to test background deliveries in the example app. If you are unable, I can give a second shot next week.
Almost there, no crash occurs with your changes. Do you plan to use "hasListeners" since you added NSNotificationCenter to emitEventWithName?
Same here, any solutions?
I've managed to avoid the crashes with the commit below, but this needs further reviews. https://github.com/Nolascoin/react-native-health/commit/0ec446385963887aaf176531dfa1a88b85e0001f
Did you guys enable background observers under Signing & Capabilities > All in your .xcworkspace file? I had it enabled under Signing & Capabilities > Release, so the background wouldn't work in development mode.
I have crash report. Maybe it help solve problem with crash application when we use background observer Version: 1.10
0 libsystem_platform.dylib 0x221be0ff8 _platform_strlen + 56 1 libicucore.A.dylib 0x1b0760ba8 icu::StringPiece::StringPiece(char const*) + 36 2 libicucore.A.dylib 0x1b086e888 0x1b070c000 + 1452168 3 libicucore.A.dylib 0x1b086eabc icu::MeasureUnit::initCurrency(icu::StringPiece) + 148 4 libicucore.A.dylib 0x1b0821a40 icu::CurrencyUnit::CurrencyUnit() + 136 5 libicucore.A.dylib 0x1b0897a98 icu::number::impl::MutablePatternModifier::MutablePatternModifier(bool) + 124 6 libicucore.A.dylib 0x1b088b67c 0x1b070c000 + 1570428 7 libicucore.A.dylib 0x1b088a4dc 0x1b070c000 + 1565916 8 libicucore.A.dylib 0x1b0889860 icu::number::LocalizedNumberFormatter::formatImpl(icu::number::impl::UFormattedNumberData*, UErrorCode&) const + 132 9 libicucore.A.dylib 0x1b08f91c0 icu::SimpleDateFormat::zeroPaddingNumber(icu::NumberFormat const*, icu::UnicodeString&, int, int, int) const + 756 10 libicucore.A.dylib 0x1b08f78c4 icu::SimpleDateFormat::subFormat(icu::UnicodeString&, char16_t, int, UDisplayContext, int, char16_t, icu::FieldPositionHandler&, icu::Calendar&, UErrorCode&) const + 1668 11 libicucore.A.dylib 0x1b08f705c icu::SimpleDateFormat::_format(icu::Calendar&, icu::UnicodeString&, icu::FieldPositionHandler&, UErrorCode&) const + 520 12 libicucore.A.dylib 0x1b08f6e34 icu::SimpleDateFormat::format(icu::Calendar&, icu::UnicodeString&, icu::FieldPosition&) const + 84 13 libicucore.A.dylib 0x1b0822750 icu::DateFormat::format(double, icu::UnicodeString&, icu::FieldPosition&) const + 176 14 libicucore.A.dylib 0x1b092c760 udat_format + 352 15 CoreFoundation 0x1b09fabb8 __cficu_udat_format + 68 16 CoreFoundation 0x1b0a08a18 CFDateFormatterCreateStringWithAbsoluteTime + 172 17 Foundation 0x1b21dc1e8 -[NSDateFormatter stringForObjectValue:] + 180
18 Test Project 0x100ba6320 +[RCTAppleHealthKit(Utils) buildISO8601StringFromDate:] + 516896 (RCTAppleHealthKit+Utils.m:0) 19 Test Project 0x100b9c4dc __91-[RCTAppleHealthKit(Queries) fetchSamplesOfType:unit:predicate:ascending:limit:completion:]_block_invoke_2 + 476380 (RCTAppleHealthKit+Queries.m:0)
20 libdispatch.dylib 0x1b06bae6c _dispatch_call_block_and_release + 32 21 libdispatch.dylib 0x1b06bca30 _dispatch_client_callout + 20 22 libdispatch.dylib 0x1b06caf48 _dispatch_main_queue_drain + 928 23 libdispatch.dylib 0x1b06cab98 _dispatch_main_queue_callback_4CF + 44 24 CoreFoundation 0x1b0a0d800 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 16 25 CoreFoundation 0x1b09c7704 __CFRunLoopRun + 2532 26 CoreFoundation 0x1b09dabc8 CFRunLoopRunSpecific + 600 27 GraphicsServices 0x1ccb46374 GSEventRunModal + 164 28 UIKitCore 0x1b334eb58 -[UIApplication _run] + 1100 29 UIKitCore 0x1b30d0090 UIApplicationMain + 364 30 Test Project 0x100b2e668 main + 26216 (main.m:7) 31 dyld 0x1011bdda4 start + 520
Please look at this : [RCTAppleHealthKit(Utils) buildISO8601StringFromDate:] - maybe error here
I'm on RN 0.72.0 & Xcode 14.0.1 on an M1 Mac and can also say that downgrading from 1.13.0 to 1.10.0 works for me on an iPhone8 device and simulator.
On 1.13.0 I see the same error as AlexNolasco:
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.
Fixed by #228
Thank you very much for your contribution @Nolascoin 🚀
Fix released in 1.13.5
Apple health causing crash the app repeatedly in background.
Apple health causing crash the app repeatedly in background.
Did it start after applying this patch?
I have removed this [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge]; from Appdelegate.m but it still crashing in background again and again.
I have removed this [[RCTAppleHealthKit new] initializeBackgroundObservers:bridge]; from Appdelegate.m but it still crashing in background again and again.
Does it work with a previous version?
In previous version the crashes were to much but now it is reduced.
Hello @Sharf8351 could you provide more information about the crash? A crash report would be great