mirror of
https://github.com/zhigang1992/react-native-notifications.git
synced 2026-06-14 01:54:58 +08:00
57 lines
1.4 KiB
Objective-C
57 lines
1.4 KiB
Objective-C
#import "RNEventEmitter.h"
|
|
|
|
@implementation RNEventEmitter
|
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
-(NSArray<NSString *> *)supportedEvents {
|
|
return @[RNRegistered,
|
|
RNRegistrationFailed,
|
|
RNPushKitRegistered,
|
|
RNNotificationReceived,
|
|
RNNotificationOpened,
|
|
RNPushKitNotificationReceived];
|
|
}
|
|
|
|
- (instancetype)init {
|
|
self = [super init];
|
|
for (NSString *event in [self supportedEvents]) {
|
|
[self addListener:event];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
+ (BOOL)requiresMainQueueSetup {
|
|
return YES;
|
|
}
|
|
|
|
# pragma mark public
|
|
|
|
+ (void)sendEvent:(NSString *)event body:(NSDictionary *)body {
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:event
|
|
object:self
|
|
userInfo:body];
|
|
}
|
|
|
|
# pragma mark private
|
|
|
|
- (void)startObserving {
|
|
for (NSString *event in [self supportedEvents]) {
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(handleNotification:)
|
|
name:event
|
|
object:nil];
|
|
}
|
|
}
|
|
|
|
- (void)stopObserving {
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
}
|
|
|
|
- (void)handleNotification:(NSNotification *)notification {
|
|
[self sendEventWithName:notification.name body:notification.userInfo];
|
|
}
|
|
|
|
|
|
@end
|