Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native NativeModules Empty Object

Trying to create my first npm module in order to determine if a user is on the phone. It's for a React Native app. No matter what I try, the module returns undefined. NativeModules always appears to be an empty object.

Please help! Below is a link to the code. export default RNOnPhoneCall; in index.js will only return undefined. How do I link the functions in ios folder, and export them in index.js? Heads up, android is not up to date yet, only ios.

Link to Github

like image 977
Tori Huang Avatar asked Sep 05 '26 09:09

Tori Huang


2 Answers

After snooping around a little, I found out that the Obj-C file isn't added to the Compile Sources in Xcode. Just follow me: Let's say the file names are: NotchNative.h and NotchNative.m. If the NotchNative.m file is not listed, the files will not be compiled by Xcode hence it needs to be added to the Compile Sources.

enter image description here

Follow the steps in the image and rebuild/run the iOS app again. It's surely a fault on the Xcode side, as it doesn't happen in case of Swift projects.

like image 89
rule_it_subir Avatar answered Sep 06 '26 23:09

rule_it_subir


Try rebuilding your project. I faced the same issue recently and simply rebuilding resolved it

like image 23
Blessing Avatar answered Sep 06 '26 23:09

Blessing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!