Skip to content

[Bug]: ForegroundWillDisplay is never called #770

@AdamFrisby

Description

@AdamFrisby

What happened?

The following code never seems to fire - we never get the "Preventing or Allowing display of notification" message in our logs.

Environment:
Unity: 2021.3.44f1
OneSignal SDK: 5.1.10 (Android + iOS)

            OneSignalSDK.OneSignal.Initialize(appId);
            OneSignalSDK.OneSignal.Notifications.ForegroundWillDisplay += NotificationsOnForegroundWillDisplay;
            // A log message here fires successfully

and...

    private static void NotificationsOnForegroundWillDisplay(object sender, NotificationWillDisplayEventArgs e)
    {
        if (_focused && CoreNetworkingService.Instance != null && CoreNetworkingService.Instance.ShouldBeLoggedIn)
        {
            Debug.Log($"Preventing display of notification -> {e.Notification.Title}: {e.Notification.Body}");
            e.PreventDefault();
        }
        else
        {
            Debug.Log($"Allowing display of notification -> {e.Notification.Title}: {e.Notification.Body}");
        }
    }

We need to use this to re-route notifications when the app is in the foreground. The log message is never logged, and the notification does display in the foreground on device.

Steps to reproduce?

1. See code above
2. Send push notification from backend service that targets the user on device
3. Observe the suppress never happens, nor any logging

What did you expect to happen?

  1. The event to fire as expected, and the notification to be likely suppressed.

Unity version

2021.3.44f1

OneSignal Unity SDK version

5.1.10

Platform

iOS, Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions