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

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐