OneSignal-Unity-SDK icon indicating copy to clipboard operation
OneSignal-Unity-SDK copied to clipboard

[Bug]: NotificationOpened method is not triggering when app is not running state for iOS

Open Omerspyke opened this issue 3 years ago • 6 comments

What happened?

This works on Android builds and used to work on iOS but recently stopped working after the update to the OneSignal 3.x.x sdk

I register "OneSignal.Default.NotificationOpened" method with OneSignal registration.

After I moved to the home screen (app is background state), I recieve a notification with additional data. If I click on this notification the app is opened and triggered "NotificationOpened" event. So, everything is fine (works both android and iOS).

Following not working situation: When my app is not running if I get a new notification (same as the working above), I click on it, app opens but "NotificationOpened" is not triggered.

-Works on Android (version 2.x.x) -Works on Android (version 3.x.x) -Works on iOS (version 2.x.x) -Not Work on iOS (version 3.x.x)

Steps to reproduce?

Install the OneSignal SDK (v3.x.x) using package manager into your project
Initialize the SDK
Register OneSignal.Default.NotificationOpened += OnNotificationOpened;
Send a push notification when app is not running or killed
Attempt to receive a push notification when app is not running (can try both android and iOS)
Tap push notification and open app
"OnNotificationOpened" method triggers for android not trigger for iOS

What did you expect to happen?

Unity version

2020.3.12.f1

OneSignal Unity SDK version

3.x.x

Platform

iOS

Unity version

2020.3.12.f1

OneSignal Unity SDK version

3.0.1

Platform

iOS

Relevant log output

No response

Code of Conduct

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

Omerspyke avatar Jun 09 '22 07:06 Omerspyke

I have the same problem on SDK version 3.0.2 and Unity 2021 LTS if I add Firebase Cloud Messaging and Firebase Auth packages to the project. Firebase Cloud Messaging is needed to get a token.

SergeiEfimik avatar Jun 25 '22 17:06 SergeiEfimik

@mistralas Can you attempt to change the order to setup the NotificationOpened before initializing OneSignal?

Register OneSignal.Default.NotificationOpened += OnNotificationOpened;
Initialize the SDK

jkasten2 avatar Jun 28 '22 05:06 jkasten2

@SergeiEfimik Your issue is unrelated to this one, could you open a new issue with more details?

jkasten2 avatar Jun 28 '22 05:06 jkasten2

@jkasten2 issue with details here: #521

SergeiEfimik avatar Jul 04 '22 07:07 SergeiEfimik

@jkasten2 Problem solved !! Thanks for the support

@mistralas Can you attempt to change the order to setup the NotificationOpened before initializing OneSignal?

Register OneSignal.Default.NotificationOpened += OnNotificationOpened;
Initialize the SDK

@jkasten2 Problem solved !! Thanks for the support

Omerspyke avatar Jul 18 '22 05:07 Omerspyke

I use this order, but it did not solve the problem (details in #521).

[SerializeField] private string _applicationID;

private void Start()
{
    OneSignal oneSignal = OneSignal.Default;
    oneSignal.LogLevel = LogLevel.Info;
    oneSignal.AlertLevel = LogLevel.Error;
    oneSignal.RequiresPrivacyConsent = _isPrivacyConsentRequired;

    oneSignal.NotificationWillShow += OnNotificationReceived;
    oneSignal.NotificationOpened += OnNotificationOpened;

    oneSignal.PushSubscriptionStateChanged += OnSubscriptionChanged;
    oneSignal.NotificationPermissionChanged += OnPermissionChanged;

    oneSignal.Initialize(_applicationID);
}

SergeiEfimik avatar Jul 18 '22 07:07 SergeiEfimik