Skip to content

Commit

Permalink
Merge pull request #1601 from essaji/rel/rn_5.0.3
Browse files Browse the repository at this point in the history
Fix: prevent addNotificationForegroundLifecycleListener getting called multiple times
  • Loading branch information
jennantilla authored Dec 5, 2023
2 parents 19d5950 + e43f4fe commit 17b9d8c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ios/RCTOneSignal/RCTOneSignalEventEmitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ @implementation RCTOneSignalEventEmitter {
BOOL _hasSetSubscriptionObserver;
BOOL _hasSetPermissionObserver;
BOOL _hasAddedNotificationClickListener;
BOOL _hasAddedNotificationLifecycleListener;
BOOL _hasAddedNotificationForegroundLifecycleListener;
BOOL _hasAddedInAppMessageClickListener;
BOOL _hasAddedInAppMessageLifecycleListener;
NSMutableDictionary* _preventDefaultCache;
Expand Down Expand Up @@ -264,7 +264,10 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
}

RCT_EXPORT_METHOD(addNotificationForegroundLifecycleListener) {
[OneSignal.Notifications addForegroundLifecycleListener:self];
if (!_hasAddedNotificationForegroundLifecycleListener) {
[OneSignal.Notifications addForegroundLifecycleListener:self];
_hasAddedNotificationForegroundLifecycleListener = true;
}
}

RCT_EXPORT_METHOD(onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event){
Expand Down Expand Up @@ -424,4 +427,4 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
// iOS Stub
}

@end
@end

0 comments on commit 17b9d8c

Please sign in to comment.