Reputation: 498
I am wondering what is the best way for adding a initialisation step to my RCTBridgeModule.
My current solution is to declare a method which has to be called inside the AppDelegate.
Are there any other/better solutions that would not require end consumers of the module to add code to their AppDelegate?
MyModule.h
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
@interface MyModule : RCTEventEmitter <RCTBridgeModule>
- (void) initialize;
@end
MyModule.m
#import "MyModule.h"
@implementation MyModule
RCT_EXPORT_MODULE();
- (void) initialize
{
// do some stuff
}
@end
Upvotes: 3
Views: 1522
Reputation: 498
I got it working by overriding the init method. This is now also documented (kind of https://facebook.github.io/react-native/docs/native-modules-ios#dependency-injection).
- (instancetype)init
{
self = [super init];
NSLog(@"Do some stuff here");
return self;
}
Upvotes: 2