OneSignal / OneSignal-Unity-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Other
222 stars 61 forks source link

[Bug]: 3.0.2 OneSignal SDK notifications reach devices but callbacks (OneSignal.NotificationOpened, OneSignal..NotificationWillShow) don't fire on iOS #521

Open egorfootball opened 2 years ago

egorfootball commented 2 years ago

What happened?

In our project we use:

  1. OneSignal SDK for remote notifications
  2. Several Firebase SDKs (Firebase Auth, Firebase Cloud Messaging, Firebase Crashlytics) 2.1 Firebase Auth for authentication users. 2.2 Firebase Crashlytics as crash reporting solution 2.3 Firebase Cloud Messaging (for receiving device token - needed to track uninstall in the AppsFlyer on the Anroid platform). More info - https://support.appsflyer.com/hc/en-us/articles/4408933557137-Uninstall-measurement (Android sections) https://dev.appsflyer.com/hc/docs/uninstall-measurement-android
  3. Mobile Notifications package for receiving device token - needed to track uninstall in the AppsFlyer on the iOS platform). More info - https://support.appsflyer.com/hc/en-us/articles/4408933557137-Uninstall-measurement (iOS section) https://docs.unity3d.com/Packages/com.unity.mobile.notifications@2.0/manual/iOS.html ("Device token" section) https://dev.appsflyer.com/hc/docs/uninstall-measurement-ios

The build is successful in Unity (XCode) and runs on the device without errors.

  1. Run application on the device - "Main" scene successfully loaded.
  2. Application enters background.
  3. Successfully send notification in the OneSignal dashboard.
  4. Device successfully receiving notification (notification appears in the top corner).
  5. User taps on the notification. Application enters foreground.
  6. OneSignal callbacks (OneSignal.Default.NotificationOpened, OneSignal.Default.NotificationWillShow) don't fire on the iOS platform.

On the Android platform everything is working successfully (OneSignal callbacks successfully fire).

Recap

  1. OneSignalExample (SDK 3.0.2) + Firebase (9.1.0) + Mobile Notifications (2.0.2) (make Authorization request) - issue REPRODUCED (OneSignal notifications reach devices BUT callbacks (OneSignal.Default.NotificationOpened, OneSignal.Default.NotificationWillShow) don't fire on iOS).

    1.1 Initialization order doesn't matter. I tried several options: -OneSignal initialization (subscribe on the OneSignal callbacks, initialize OneSignal SDK), Firebase initialization (check Firebase dependencies, optional subscribe on the Firebase Cloud Messaging callbacks), Mobile Notifications initialization (make Authorization request) -Firebase initialization, OneSignal initialization, Mobile Notifications initialization -Other options 1.2 Tried on/off different options in the Mobile Notifications project settings ("Enable push notification", "Request Authorization on App Launch", "Register for Push Notifications on App Launch"). It doesn't matter. Following options are default: 1.3 Tried subscribe/don't subscribe on the Firebase Cloud Messaging callbacks (FirebaseMessaging.MessageReceived, FirebaseMessaging.TokenReceived) after Firebase initialization. It doesn't matter. 1.4 If subscribed on the Firebase Cloud Messaging callbacks (FirebaseMessaging.MessageReceived, FirebaseMessaging.TokenReceived) then reproduce issue - device logs would contain log about receiving notification by Firebase Cloud Messaging. "FCM: Received notification through notification center." "FCM: userInfo: { aps = { alert = { body = "test2 message"; subtitle = "test2 subtitle"; title = "Test2 Title"; }; "interruption-level" = active; "mutable-content" = 1; "relevance-score" = 0; sound = default; } };"

    FirebaseMessaging.MessageReceived callback successfully fires, BUT OneSignal.NotificationOpened callback doesn't fire.

  2. OneSignalExample (SDK 2.14.6) + Firebase (9.1.0) + Mobile Notificatinons (2.0.2) (make Authorization request) - issue NOT reproduced. OneSignal SDK 2.14.6 - previous version used in the our project before update to the OneSignal SDK 3.x.x.

  3. OneSignalExample (SDK 3.0.2) + Firebase (9.1.0) - issue NOT reproduced.

  4. OneSignalExample (SDK 3.0.2) + Mobile Notifications (2.0.2) (make Authorization request) - issue NOT reproduced

  5. OneSignalExample (SDK 3.0.2) - issue NOT reproduced

System information:

  1. Xcode Version 13.4 (13F17a)
  2. macOS Monterey 12.4
  3. Cocapods 1.11.3

I prepared several examples for to simplify the reproduction of the issue:

  1. OneSignalExample + Mobile Notifications OneSignalExampleWithMobileNotifications.zip
  2. OneSignalExample + Firebase (Auth, Crashlytics, CloudMessaging) - remove files related to the Firebase SDKs due to upload file limiting. After extracting example, open it in the Unity and add Firebase SDK. OneSignalExampleWithFirebase.zip
  3. OneSignalExample + Firebase (Auth, Crashlytics, CloudMessaging) + Mobile Notifications - remove files related to the Firebase SDKs due to upload file limiting. After extracting example, open it in the Unity and add Firebase SDK. OneSignalExampleWithFirebaseAndMobileNotifications.zip

Steps to reproduce?

1. Download OneSignal SDK 3.0.2
2. Open OneSignalExample (https://github.com/OneSignal/OneSignal-Unity-SDK/tree/main/OneSignalExample)
3. Import following Firebase SDKs(Firebase.Auth, Firebase.Crashlytics, Firebase.CloudMessaging). Firebase version is 9.1.0. Firebase SDKs can be downloaded from https://developers.google.com/unity/archive.
4. Import Mobile Notifications package (version 2.0.2). https://docs.unity3d.com/Packages/com.unity.mobile.notifications@2.0/manual/index.html
6. Open OneSignalExampleScene scene in the Unity Editor.
7. Initialize Firebase. In our example add new GameObject ("FirebaseInit") to the OneSignalExampleScene scene, then add FirebaseInit script to that GameObject. 
6. Make Authorization request and receive device token. In our example add new GameObject ("MobileNotificationsInit"), then add MobileNotificationsInit script to that GameObject.
8. Switch platform to the iOS if not yet.
9. Build project (from Unity and Xcode). Install application on the device (iPhone or iPad. It doesn't matter).
10. Run application on device.
11. Wait until OneSignalExampleScene scene opened and click "Initialize SDK" button.
12. Application enters background.
13. Send notification to the device from the OneSignal dashboard.
14. Wait until device receiving notification. 
15. Tap on the notification.
16. Application enters foreground.
17. Check device logs. No logs related to the OneSignal callbacks (OneSignal.NotificationOpened, OneSignal.NotificationWillShow).

What did you expect to happen?

Final application (OneSignalExample (v 3.0.2) + Firebase (v.9.1.0) (Auth, Crashlytics, Cloud Messaging) + Mobile Notification (v 2.0.2) (make Authorization request for receiving device token) works correctly with incoming push notifications - OneSignal callbacks (OneSignal.NotificationOpened, OneSignal.NotificationWillShow) successfully fire.

Unity version

2021.3.5f1

OneSignal Unity SDK version

3.0.2

Platform

iOS

Relevant log output

No response

Code of Conduct

Goropocha commented 2 years ago

I have the same issue. Here are my environments:

ricky6982 commented 1 year ago

I have the same issue, could you solve this issue?

mpiechocki commented 1 year ago

Have the same issue. Anybody found a solution to how to stop pushes from appearing while the app is in foreground?