Skip to content

Commit 17b9d8c

Browse files
authored
Merge pull request #1601 from essaji/rel/rn_5.0.3
Fix: prevent addNotificationForegroundLifecycleListener getting called multiple times
2 parents 19d5950 + e43f4fe commit 17b9d8c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ios/RCTOneSignal/RCTOneSignalEventEmitter.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ @implementation RCTOneSignalEventEmitter {
1010
BOOL _hasSetSubscriptionObserver;
1111
BOOL _hasSetPermissionObserver;
1212
BOOL _hasAddedNotificationClickListener;
13-
BOOL _hasAddedNotificationLifecycleListener;
13+
BOOL _hasAddedNotificationForegroundLifecycleListener;
1414
BOOL _hasAddedInAppMessageClickListener;
1515
BOOL _hasAddedInAppMessageLifecycleListener;
1616
NSMutableDictionary* _preventDefaultCache;
@@ -264,7 +264,10 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
264264
}
265265

266266
RCT_EXPORT_METHOD(addNotificationForegroundLifecycleListener) {
267-
[OneSignal.Notifications addForegroundLifecycleListener:self];
267+
if (!_hasAddedNotificationForegroundLifecycleListener) {
268+
[OneSignal.Notifications addForegroundLifecycleListener:self];
269+
_hasAddedNotificationForegroundLifecycleListener = true;
270+
}
268271
}
269272

270273
RCT_EXPORT_METHOD(onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event){
@@ -424,4 +427,4 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
424427
// iOS Stub
425428
}
426429

427-
@end
430+
@end

0 commit comments

Comments
 (0)