Skip to content

Commit 64ebca3

Browse files
authored
Merge pull request #635 from OneSignal/fix/preventDefault
[Fix] PreventDefualt on iOS
2 parents 0c1f3d9 + 2ae5973 commit 64ebca3

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

OneSignalExample/Assets/OneSignal/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Stop foreground notifications from displaying after calling prevent default on iOS
10+
811
## [5.0.1]
912
### Fixed
1013
- Push subscription Id and Token malloc error on iOS

com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ - (instancetype) init {
7171
[OneSignal.Notifications addPermissionObserver:self];
7272
[OneSignal.Notifications addForegroundLifecycleListener:self];
7373
[OneSignal.Notifications addClickListener:self];
74+
75+
_willDisplayEvents = [NSMutableDictionary new];
7476
}
7577

7678
return self;
@@ -84,10 +86,10 @@ - (void)onNotificationPermissionDidChange:(BOOL)permission {
8486

8587
- (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
8688
if (_willDisplayDelegate != nil) {
89+
_willDisplayEvents[event.notification.notificationId] = event;
90+
8791
NSString *stringNotification = [event.notification stringify];
8892
_willDisplayDelegate([stringNotification UTF8String]);
89-
90-
_willDisplayEvents[event.notification.notificationId] = event;
9193
}
9294
}
9395

com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static void _onForegroundWillDisplay(string notification) {
114114
{
115115
// We use Send instead of Post because we need to *not* return to our caller until the
116116
// event handlers have returned themselves. This allows a handler to call PreventDefault()
117-
// which will get passed down to Android in InternalNotificationWillDisplayEventArgs.
117+
// which will get passed down to iOS in InternalNotificationWillDisplayEventArgs.
118118
UnityMainThreadDispatch.Send(state => handler(_instance, args));
119119
}
120120
}

0 commit comments

Comments
 (0)