Skip to content

[Question] Push notification messages are not displayed in the closed/background app on launch #1111

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

Closed
equizo opened this issue Aug 9, 2021 · 15 comments
Labels
api: messaging closed-by-bot needs-info Need information for the developer stale Don't have recent activity type: question

Comments

@equizo
Copy link

equizo commented Aug 9, 2021

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.3.10
  • Firebase Unity SDK version: 8.1.0
  • Source you installed the SDK: unitypackage
  • Problematic Firebase Component: Messaging
  • Other Firebase Components in use: Analytics, Deepliinks, Crashlytics,
  • Additional SDKs you are using: Facebook, IronSource
  • Platform you are using the Unity editor on Windows
  • Platform you are targeting: Android
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the question here:

Push notification messages are not received in the app if the app is either closed or is in the background. The foreground app receives messages OK.

queued message 0:1628115171791201%bfe3fe3bbfe3fe3b
Firebase.AppUtilPINVOKE:PollCallbacks()
Firebase.AppUtil:PollCallbacks()
Firebase.Platform.FirebaseHandler:Update()

and

2021-08-10 00:14:38.207 23350-23465/com.threed_view.FluentWorldsDev E/Unity: Couldn't parse the message: Object reference not set to an instance of an object.
    VIEW.VCT.Common.VCTLog:Error(String, String)
    VIEW.VCT.Common.VCTLog:CatchLogs(String, String, LogType)
    UnityEngine.LogCallback:Invoke(String, String, LogType)
    VIEW.VCT.Common.MessagingService:OnMessageReceived(Object, MessageReceivedEventArgs)
    System.EventHandler`1:Invoke(Object, TEventArgs)
    Firebase.Messaging.<MessageReceivedDelegateMethod>c__AnonStorey0:<>m__0()
    System.Func`1:Invoke()
    Firebase.ExceptionAggregator:Wrap(Func`1, T)
    Firebase.AppUtilPINVOKE:PollCallbacks()
    Firebase.AppUtil:PollCallbacks()
    Firebase.Platform.FirebaseHandler:Update()

2021-08-10 00:01:16.109 20990-21989/com.threed_view.FluentWorldsDev W/FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.

So I guess I somehow missing on queued message handling when app is launched?

@paulinon paulinon removed the new New issue. label Aug 10, 2021
@vimanyu
Copy link
Contributor

vimanyu commented Aug 11, 2021

Hi,
Thank you for creating this issue. It would help to have some more information to be able to debug this more efficiently.
Could you try reproducing this issue in our quickstart-unity test app?

I did a quick test on our app and it worked as expected. Here are the steps I performed,

  1. Clone our github repo locally and navigate to messaging/testapp
  2. Place a valid "google-services.json" for your project into Assets/
  3. Open in Unity (I used Unity 2020.1.7f1) and change Build settings to Android and update the bundle identifier in "Player Settings -> Android -> Other settings -> Identification -> Package name" to something that corresponds with your google-services.json.
  4. Build and Run (I am using a Pixel 5 for my test)
  5. Sending message from Firebase console with some data in it and here is the behavior on the app,
State Result
App in foreground Message received and you can see the notification details (title, body) along with data
App in background Clicking notification opens the app and shows the data

Let me know if you need more details but I am curious if you are seeing similar behavior on your end.

@cynthiajoan cynthiajoan added the needs-info Need information for the developer label Aug 12, 2021
@equizo
Copy link
Author

equizo commented Aug 12, 2021 via email

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Aug 12, 2021
@vimanyu
Copy link
Contributor

vimanyu commented Aug 16, 2021

Hi @equizo,
Thanks for responding but I am not sure if I understand the behavior of the app on your end. Is the OnMessageReceived not triggering only when the app was killed and a notification was received in the background? (I tried both cases, kill app and send background notification, background app and send background notification, and both of them worked as per the table above).
Does the notification work when you send it while the app is in background (not killed)?
Please note that you will only see "data" fields from background notifications.

Which event are you sending from Unity?

@equizo
Copy link
Author

equizo commented Aug 16, 2021

@vimanyu
That's correct. When the app is in foreground/background - no issues, I can see OnMessageReceived triggered in Unity.
Only when the app is killed I don't see any triggering in the app. Notifications are received in all cases, but there is nowhere I can track this in the app. I need to know if the app was open from notification, for that, I send a firebase analytics event in OnMessageReceived, and the Debug.Log calls to track locally in the LogCat once I tap the notification.
The builds are done in Android Studio (Unity -> export Android project).

Could you tell how do you get if "data" was received on the device? Also, do you send the notifications from the FCM console?

@cynthiajoan
Copy link
Contributor

Hi @equizo,

From what I know, here's a quote of this issue:

The Android framework advises that apps that have been stopped (i.e. killed/force-stopped from Settings) should not be started without explicit user interaction. FCM follows this recommendation, and thus does not deliver messages to stopped apps. Here are some documentation that discuss this topic:

Life of a message from FCM to the device Using Firebase Cloud
Messaging with Android O

So this is an expected behavior that app's killed would not receive FCM notification.

@cynthiajoan cynthiajoan added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Aug 17, 2021
@equizo
Copy link
Author

equizo commented Aug 17, 2021

hi @cynthiajoan
Excuse me I did not mean settings kill/force stop. But just close the app, meaning it is no longer minimized/(background?) but just is in the "cold" state, not being recently launched. Is this is what it means? The notifications are still received by the device. But there is no way to trigger OnMessageReceived or any other way of verifying if the app was open from the notification.

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Aug 17, 2021
@equizo
Copy link
Author

equizo commented Aug 23, 2021

@cynthiajoan

I followed the documentation and created another project from scratch. Still no data for iOS. Please find the source files attached as well as Xcode console log
https://drive.google.com/drive/folders/1k6pb6oKmsYYOATSBOLDI4rjGbn-PfbWe?usp=sharing

image

@alexames
Copy link

Are the messages showing up in the system tray? If so, does tapping on them start up the app that is in the background? If so, does the app re-start or does it continue where it left off?

@equizo
Copy link
Author

equizo commented Aug 31, 2021

Are the messages showing up in the system tray? If so, does tapping on them start up the app that is in the background? If so, does the app re-start or does it continue where it left off?

Yes, the behavior is as expected. If the app was minimized - then it will proceed, otherwise, start.

@alexames
Copy link

alexames commented Sep 2, 2021

In the original post you commented that you were targeting Android, but now it sounds like you're targeting iOS. Can you clarify whether this issue occurring on Android or iOS (or both)?

So is this an accurate description of what is happening?

  1. App is open but in the background
  2. Message is sent
  3. A notification appears in the system tray
  4. You tap the notification in the system tray
  5. The app opens, but the OnMessageReceived call back is not triggered

Is that correct?

@equizo
Copy link
Author

equizo commented Sep 2, 2021

@alexames excuse me, ios post I got mixed up with another thread.
5. The app opens, an OnMessageReceived is triggered.
This works fine if the app is in background mode.
OnMessageReceived is not triggered (or I need a way to trigger it somehow from Gradle) when the app is not launched.

@chkuang-g
Copy link
Contributor

@equizo

I tried to reproduce it with the following configuration, but I can get the OnMessageReceived event properly after I subscribe a topic, kill the app, send the message through Firebase console and click on the notification.

  • Built with Unity 2020.3.18f1
  • FCM Unity testapp
  • Firebase Unity SDK 8.1.0
  • Built Android apk and deployed to a physical Pixel device (my phone :$)

Here is what I did after the app was deployed:

  1. Launched the app for the first time.
  2. Picked a topic and click on Subscribe button.
  3. Send a message from Firebase console and confirm the message is received when the app is in the foreground.
  4. Killed the app.
  5. Sent another message from Firebase console. Confirmed the notification is received on the device.
  6. Clicked on the notification, confirmed the message is received in Unity app.

Here is a screenshot of the app for the second launch.
Screenshot_20210914-185520

I would be great if you can help us to diagnose the issue with the following steps.

  1. Try to run the steps I described above and see if you reproduce the issue using FCM quickstart,
  2. Either with the quickstart or your app, try to see if there is any abnormal logs using adb logcat when the issue occurs.
  3. This issue Android Firebase 8.0.0 TokenReceived called only on application reinstall #1088 sometimes can prevent the async FCM APIs from finishing with some configurations. This only occurs from 8.0.0. Could you try to downgrade to 7.2.0 and see if the issue still occurs? Or FWIW, upgrade to 8.2.0 and see if anything changed. You should find all the .unitypackage you need from this page (FCM, Crashlytics and Analytics)

Appreciate it.
Shawn

@chkuang-g chkuang-g added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Sep 15, 2021
@equizo
Copy link
Author

equizo commented Sep 15, 2021

@chkuang-g thank you. Will give it a shot once have a chance to!

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed needs-info Need information for the developer labels Sep 15, 2021
@DellaBitta DellaBitta added needs-info Need information for the developer and removed needs-attention Need Googler's attention labels Sep 20, 2021
@google-oss-bot google-oss-bot added the stale Don't have recent activity label Sep 22, 2021
@google-oss-bot
Copy link

Hey @equizo. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link

Since there haven't been any recent updates here, I am going to close this issue.

@equizo if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Oct 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: messaging closed-by-bot needs-info Need information for the developer stale Don't have recent activity type: question
Projects
None yet
Development

No branches or pull requests

8 participants