RNEventEmitter.m 958 Bytes
Newer Older
yogevbd's avatar
WIP  
yogevbd committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#import "RNEventEmitter.h"

@implementation RNEventEmitter

RCT_EXPORT_MODULE();

-(NSArray<NSString *> *)supportedEvents {
    return @[Registered,
             RegistrationFailed,
             PushKitRegistered,
             NotificationReceivedForeground,
             NotificationReceivedBackground,
             NotificationOpened,
             NotificationActionReceived];
}

# pragma mark public

+ (instancetype)sharedInstance {
    static RNEventEmitter *sharedInstance = nil;
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        sharedInstance = [[RNEventEmitter alloc] init];
    });
    return sharedInstance;
}

+ (void)sendEvent:(NSString *)event body:(NSDictionary *)body {
    [[self sharedInstance] send:event body:body];
}


# pragma mark private

- (void)send:(NSString *)eventName body:(id)body {
    if (self.bridge == nil) {
        return;
    }
    [self sendEventWithName:eventName body:body];
}

@end