66#pragma GCC diagnostic push
77#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
88
9+ @interface RCTOneSignalEventEmitter ()
10+ - (void )emitEventWithName : (NSString *)name body : (NSDictionary *)body ;
11+ @end
12+
913@implementation RCTOneSignalEventEmitter {
1014 BOOL _hasSetSubscriptionObserver;
1115 BOOL _hasSetPermissionObserver;
@@ -31,12 +35,6 @@ - (instancetype)init {
3135 _preventDefaultCache = [NSMutableDictionary new ];
3236 _notificationWillDisplayCache = [NSMutableDictionary new ];
3337
34- for (NSString *eventName in OSNotificationEventTypesArray)
35- [[NSNotificationCenter defaultCenter ] addObserver: self
36- selector: @selector (emitEvent: )
37- name: eventName
38- object: nil ];
39-
4038 // Clean up previous instance if it exists (handles reload scenario)
4139 if (_currentInstance != nil && _currentInstance != self) {
4240 [_currentInstance removeHandlers ];
@@ -51,7 +49,11 @@ - (instancetype)init {
5149- (void )invalidate {
5250 [self removeHandlers ];
5351 [self removeObservers ];
54- [[NSNotificationCenter defaultCenter ] removeObserver: self ];
52+ [_preventDefaultCache removeAllObjects ];
53+ [_notificationWillDisplayCache removeAllObjects ];
54+ if (_currentInstance == self) {
55+ _currentInstance = nil ;
56+ }
5557}
5658
5759- (NSArray <NSString *> *)processNSError : (NSError *)error {
@@ -66,14 +68,11 @@ - (void)invalidate {
6668
6769#pragma mark Send Event Methods
6870
69- - (void )emitEvent : ( NSNotification *)notification {
71+ - (void )emitEventWithName : ( NSString *)name body : ( NSDictionary *) body {
7072 if (!_eventEmitterCallback) {
7173 return ;
7274 }
7375
74- NSString *name = notification.name ;
75- NSDictionary *body = notification.userInfo ;
76-
7776 if ([name isEqualToString: OSEventString (PermissionChanged)]) {
7877 [self emitOnPermissionChanged: body];
7978 } else if ([name isEqualToString: OSEventString (SubscriptionChanged)]) {
@@ -99,9 +98,7 @@ - (void)emitEvent:(NSNotification *)notification {
9998}
10099
101100+ (void )sendEventWithName : (NSString *)name withBody : (NSDictionary *)body {
102- [[NSNotificationCenter defaultCenter ] postNotificationName: name
103- object: nil
104- userInfo: body];
101+ [_currentInstance emitEventWithName: name body: body];
105102}
106103
107104#pragma mark Exported Methods
@@ -341,7 +338,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
341338 }
342339}
343340
344- RCT_EXPORT_METHOD (removePermissionObserver) {
341+ - ( void ) removePermissionObserver {
345342 if (_hasSetPermissionObserver) {
346343 [OneSignal.Notifications
347344 removePermissionObserver: [RCTOneSignal sharedInstance ]];
@@ -370,22 +367,14 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
370367
371368RCT_EXPORT_METHOD (onWillDisplayNotification : (OSNotificationWillDisplayEvent *)
372369 event) {
373- __weak RCTOneSignalEventEmitter *weakSelf = self;
374- RCTOneSignalEventEmitter *strongSelf = weakSelf;
375- if (!strongSelf)
376- return ;
377-
378- strongSelf->_notificationWillDisplayCache [event.notification.notificationId] =
379- event;
370+ _notificationWillDisplayCache[event.notification.notificationId] = event;
380371 [event preventDefault ];
381372 [RCTOneSignalEventEmitter
382373 sendEventWithName: @" OneSignal-notificationWillDisplayInForeground"
383374 withBody: [event.notification jsonRepresentation ]];
384375}
385376
386377RCT_EXPORT_METHOD (preventDefault : (NSString *)notificationId) {
387- __weak RCTOneSignalEventEmitter *weakSelf = self;
388- RCTOneSignalEventEmitter *strongSelf = weakSelf;
389378 OSNotificationWillDisplayEvent *event =
390379 _notificationWillDisplayCache[notificationId];
391380 if (!event) {
@@ -398,7 +387,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
398387 notificationId]];
399388 return ;
400389 }
401- strongSelf-> _preventDefaultCache [event.notification.notificationId] = event;
390+ _preventDefaultCache[event.notification.notificationId] = event;
402391 [event preventDefault ];
403392}
404393
@@ -442,7 +431,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
442431 }
443432}
444433
445- RCT_EXPORT_METHOD (removePushSubscriptionObserver) {
434+ - ( void ) removePushSubscriptionObserver {
446435 if (_hasSetSubscriptionObserver) {
447436 [OneSignal.User.pushSubscription
448437 removeObserver: [RCTOneSignal sharedInstance ]];
@@ -625,3 +614,5 @@ - (void)removeUserStateObserver {
625614}
626615
627616@end
617+
618+ #pragma GCC diagnostic pop
0 commit comments