Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ForegroundWillDisplay is never called #770

Closed
1 task done
AdamFrisby opened this issue Dec 3, 2024 · 1 comment
Closed
1 task done

[Bug]: ForegroundWillDisplay is never called #770

AdamFrisby opened this issue Dec 3, 2024 · 1 comment

Comments

@AdamFrisby
Copy link

AdamFrisby commented Dec 3, 2024

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
@AdamFrisby
Copy link
Author

Might have been something unique to our installation. Closing this ticket for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant