RNEventEmitter.m 1.41 KB
Newer Older
yogevbd's avatar
WIP  
yogevbd committed
1 2 3 4 5 6 7
#import "RNEventEmitter.h"

@implementation RNEventEmitter

RCT_EXPORT_MODULE();

-(NSArray<NSString *> *)supportedEvents {
yogevbd's avatar
WIP  
yogevbd committed
8 9 10 11
    return @[RNRegistered,
             RNRegistrationFailed,
             RNPushKitRegistered,
             RNNotificationReceivedForeground,
yogevbd's avatar
WIP  
yogevbd committed
12
             RNNotificationOpened];
yogevbd's avatar
WIP  
yogevbd committed
13 14
}

yogevbd's avatar
WIP  
yogevbd committed
15 16 17 18 19 20
- (instancetype)init {
    self = [super init];
    for (NSString *event in [self supportedEvents]) {
        [self addListener:event];
    }
    return self;
yogevbd's avatar
WIP  
yogevbd committed
21 22
}

yogevbd's avatar
WIP  
yogevbd committed
23 24 25 26
+ (BOOL)requiresMainQueueSetup {
    return YES;
}

yogevbd's avatar
WIP  
yogevbd committed
27 28
# pragma mark public

yogevbd's avatar
WIP  
yogevbd committed
29
+ (void)sendEvent:(NSString *)event body:(NSDictionary *)body {
yogevbd's avatar
WIP  
yogevbd committed
30 31 32
    [[NSNotificationCenter defaultCenter] postNotificationName:event
                                                        object:self
                                                      userInfo:body];
yogevbd's avatar
WIP  
yogevbd committed
33 34 35 36
}

# pragma mark private

yogevbd's avatar
WIP  
yogevbd committed
37 38 39 40 41 42
- (void)startObserving {
    for (NSString *event in [self supportedEvents]) {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(handleNotification:)
                                                     name:event
                                                   object:nil];
yogevbd's avatar
WIP  
yogevbd committed
43 44 45
    }
}

yogevbd's avatar
WIP  
yogevbd committed
46 47 48 49 50 51 52 53 54
- (void)stopObserving {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)handleNotification:(NSNotification *)notification {
    [self sendEventWithName:notification.name body:notification.userInfo];
}


yogevbd's avatar
WIP  
yogevbd committed
55
@end