Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions ios/RCTOneSignal/RCTOneSignalEventEmitter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ @implementation RCTOneSignalEventEmitter {
BOOL _hasAddedNotificationForegroundLifecycleListener;
BOOL _hasAddedInAppMessageClickListener;
BOOL _hasAddedInAppMessageLifecycleListener;
NSMutableDictionary *_preventDefaultCache;
NSMutableDictionary *_notificationWillDisplayCache;
}

Expand All @@ -66,7 +65,6 @@ + (BOOL)requiresMainQueueSetup {

- (instancetype)init {
if (self = [super init]) {
_preventDefaultCache = [NSMutableDictionary new];
_notificationWillDisplayCache = [NSMutableDictionary new];

// Clean up previous instance if it exists (handles reload scenario)
Expand All @@ -83,8 +81,9 @@ - (instancetype)init {
- (void)invalidate {
[self removeHandlers];
[self removeObservers];
[_preventDefaultCache removeAllObjects];
[_notificationWillDisplayCache removeAllObjects];
@synchronized(_notificationWillDisplayCache) {
[_notificationWillDisplayCache removeAllObjects];
}
if (_currentInstance == self) {
_currentInstance = nil;
}
Expand Down Expand Up @@ -396,16 +395,20 @@ - (void)removePermissionObserver {
}

- (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
_notificationWillDisplayCache[event.notification.notificationId] = event;
@synchronized(_notificationWillDisplayCache) {
_notificationWillDisplayCache[event.notification.notificationId] = event;
}
[event preventDefault];
[RCTOneSignalEventEmitter
sendEventWithName:@"OneSignal-notificationWillDisplayInForeground"
withBody:[event.notification jsonRepresentation]];
}

RCT_EXPORT_METHOD(preventDefault : (NSString *)notificationId) {
OSNotificationWillDisplayEvent *event =
_notificationWillDisplayCache[notificationId];
OSNotificationWillDisplayEvent *event;
@synchronized(_notificationWillDisplayCache) {
event = _notificationWillDisplayCache[notificationId];
}
if (!event) {
[OneSignalLog
onesignalLog:ONE_S_LL_ERROR
Expand All @@ -416,7 +419,6 @@ - (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
notificationId]];
return;
}
_preventDefaultCache[event.notification.notificationId] = event;
[event preventDefault];
}

Expand Down Expand Up @@ -579,8 +581,11 @@ - (void)removePushSubscriptionObserver {
RCT_EXPORT_METHOD(optOut) { [OneSignal.User.pushSubscription optOut]; }

RCT_EXPORT_METHOD(displayNotification : (NSString *)notificationId) {
OSNotificationWillDisplayEvent *event =
_notificationWillDisplayCache[notificationId];
OSNotificationWillDisplayEvent *event;
@synchronized(_notificationWillDisplayCache) {
event = _notificationWillDisplayCache[notificationId];
[_notificationWillDisplayCache removeObjectForKey:notificationId];
}
if (!event) {
[OneSignalLog
onesignalLog:ONE_S_LL_ERROR
Expand All @@ -594,9 +599,6 @@ - (void)removePushSubscriptionObserver {
dispatch_async(dispatch_get_main_queue(), ^{
[event.notification display];
});

[_preventDefaultCache removeObjectForKey:notificationId];
[_notificationWillDisplayCache removeObjectForKey:notificationId];
}

- (void)removeObservers {
Expand Down
Loading