Nicky Romeijn Nicky Romeijn - 8 months ago 36
iOS Question

How to register a React Native module on iOS

Im running into an issue with a React Native module on iOS. I wrote a module in Objective-C and used

to export the module and expose it to React Native. However when I print out the content of NativeModules it does not contain the module.

import { NativeModules } from 'react-native';
console.log("Native modules:", NativeModules);

I also wrote a similar module in Java (Android) and this works just fine. However with Android modules I know you have to register them in the MainActivity class. I'm thinking I have missed something similar with iOS but can't find it anywhere in the React Native documentation.

Would appreciate it if someone could help me out.


On iOS module are automatically registered. The bridge does this by querying all classes implementing the RCTBridgeModule protocol.

If you don't see your module, this means something is missing somewhere.

One possibility is that your ObjC class is not compiled as part of the application target. In that case open Xcode and check your {your_module}.m belongs to your app's target.

Example with the F8Scrolling module from the F8 sample app:

enter image description here