Skip to content

Commit

Permalink
Merge pull request #635 from OneSignal/fix/preventDefault
Browse files Browse the repository at this point in the history
[Fix] PreventDefualt on iOS
  • Loading branch information
shepherd-l authored and jinliu9508 committed Feb 27, 2024
2 parents 06e66f1 + aec65cd commit a9aa133
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions OneSignalExample/Assets/OneSignal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Stop foreground notifications from displaying after calling prevent default on iOS

## [5.0.1]
### Fixed
- Push subscription Id and Token malloc error on iOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ - (instancetype) init {
[OneSignal.Notifications addPermissionObserver:self];
[OneSignal.Notifications addForegroundLifecycleListener:self];
[OneSignal.Notifications addClickListener:self];

_willDisplayEvents = [NSMutableDictionary new];
}

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

- (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
if (_willDisplayDelegate != nil) {
_willDisplayEvents[event.notification.notificationId] = event;

NSString *stringNotification = [event.notification stringify];
_willDisplayDelegate([stringNotification UTF8String]);

_willDisplayEvents[event.notification.notificationId] = event;
}
}

Expand Down
2 changes: 1 addition & 1 deletion com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static void _onForegroundWillDisplay(string notification) {
{
// We use Send instead of Post because we need to *not* return to our caller until the
// event handlers have returned themselves. This allows a handler to call PreventDefault()
// which will get passed down to Android in InternalNotificationWillDisplayEventArgs.
// which will get passed down to iOS in InternalNotificationWillDisplayEventArgs.
UnityMainThreadDispatch.Send(state => handler(_instance, args));
}
}
Expand Down

0 comments on commit a9aa133

Please sign in to comment.