Регистрация наблюдателей в собственном модуле React Native на iOS (NSNotificationCenter) - PullRequest
0 голосов
/ 12 апреля 2019

Я написал собственный модуль, чтобы связать нативный код iOS (target-c) с моим нативным кодом. Я пытаюсь прослушивать события через NSNotificationCenter в собственном модуле, но я не получаю никаких событий. Я настраиваю слушателя в init в моем модуле. Я включил код, который слушает события ниже. К сожалению, похоже, мои методы никогда не запускаются. Я неправильно настроил?

- (instancetype)init
{
    self = [super init];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(receivedData:)
                                                 name:ProtocolReceivedData
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(receivedEvent:)
                                                 name:ProtocolReceivedEvent
                                               object:nil];
    return self;
}

- (void)receivedData:(NSNotification *)notification {
    NSLog(@"%@", @"NATIVE MODULE HAS RECEIVED DATA");
}

- (void)receivedEvent:(NSNotification *)notification {
    NSLog(@"%@", @"NATIVE MODULE HAS AN EVENT");
}

Код, который отправляет уведомление, выглядит так,

[[NSNotificationCenter defaultCenter] postNotificationName:ProtocolReceivedEvent
     object:self
     userInfo:userInfo];
...