How to add an extra module for bridge on iOS?

Viewed 75

I have created a new native module in my React Native application (It's called RCTAVAudioSessionModule). When looking in the AppDelegate I found this code snippet:

- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
{
    NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
    // If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here!
    return extraModules;
}

I want to add my native module to the extraModules array. I tried to do something like that:

- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
{
    NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
    // If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here!
    return [extraModules arrayByAddingObject:(RCTAVAudioSessionModule.new)];
}

However, when I try to call a method from module I get an error that says:

TypeError: null is not an object (evaluating 'RCTAVAudioSessionModule.getCurrentRoute')

How can I correctly add my native module and use it on iOS?

0 Answers
Related