RN端: const calendarManagerEmitter = new NativeEventEmitter(NativeModules.FPreNotification); const subscription = calendarManagerEmitter.addListener( 'aaaaaa', this.onDataReceived.bind(this) );
OC端:
@interface FPreNotification (){
}
@property (nonatomic, copy) NSDictionary *bodyDic;
@end
@implementation FPreNotification
RCT_EXPORT_MODULE(FPreNotification);
- (id)init
{
if (self = [super init]) {
_bodyDic = [[NSDictionary alloc] init];
}
return self;
}
// 该方法为必实现的方法 数组必须不能为空
- (NSArray<NSString *> *)supportedEvents
{
return @[@"flight-list-preSearchResult"];
}
-(void)receiveNotification:(NSNotification *)notification{
_bodyDic = notification.userInfo;
[self sendEventWithName:@"aaaaaa" body:_bodyDic];
}
- (void)startObserving
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNotification:)
name:KFPresearchForiOSNotification
object:nil];
}
-(void)stopObserving{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end