question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android Firebase 8.0.0 TokenReceived called only on application reinstall

See original GitHub issue

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2018.4.31f1
  • Firebase Unity SDK version: 8.0.0
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Messaging
  • Other Firebase Components in use: Analytics
  • Additional SDKs you are using: Google Play, Adjust, Appmetrica, DevToDev, Ironsource ad mediation( mediation networks Ironsource, UnityAds, Admob, Facebook, AdColony)
  • Platform you are using the Unity editor on: Mac 11.4
  • Platform you are targeting: iOS, Android
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the question here:

After updating the Firebase Unity SDK from version 7.1.0 to version 8.0.0, the TokenReceived event on android stopped being called after each initialization. Now now the event comes only once when installing the application. On iOS, everything is still correct. A direct call to FirebaseMessaging.GetTokenAsync returns the push token correctly.

Is this a bug or a new behavior and now we need to get a token like in android sdk and save it until the next change?

=======================================================================================

Dependencies:

com.adcolony:sdk:4.5.0
com.android.installreferrer:installreferrer:2.1
com.android.support:support-compat:26.1.0
com.android.support:support-v4:26.1.0
com.facebook.android:audience-network-sdk:6.5.0
com.google.android.gms:play-services-ads:20.1.0
com.google.android.gms:play-services-ads-identifier:17.0.0
com.google.android.gms:play-services-base:17.6.0
com.google.android.gms:play-services-basement:17.5.0
com.google.firebase:firebase-analytics:19.0.0
com.google.firebase:firebase-analytics-unity:8.0.0
com.google.firebase:firebase-app-unity:8.0.0
com.google.firebase:firebase-common:20.0.0
com.google.firebase:firebase-messaging:22.0.0
com.google.firebase:firebase-messaging-unity:8.0.0
com.google.games:gpgs-plugin-support:0.10.12
com.ironsource.adapters:adcolonyadapter:4.3.8
com.ironsource.adapters:admobadapter:4.3.20
com.ironsource.adapters:facebookadapter:4.3.27
com.ironsource.adapters:unityadsadapter:4.3.11
com.ironsource.sdk:mediationsdk:7.1.6
com.tapjoy:tapjoy-android-unitybridge:12.8.1
com.unity3d.ads:unity-ads:3.7.2

We are using manual initialization.

Android manifest:

<service android: name = "com.google.firebase.messaging.MessageForwardingService" android: permission = "android.permission.BIND_JOB_SERVICE" android: exported = "false" />
<meta-data android: name = "firebase_messaging_auto_init_enabled" android: value = "false" />
<meta-data android: name = "firebase_analytics_collection_enabled" android: value = "false" />

Our initialization code:

FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
{
	DependencyStatus dependencyStatus = task.Result;

	if (dependencyStatus == DependencyStatus.Available)
	{
		m_firebaseInstance = FirebaseApp.DefaultInstance;

		if (PluginManager.Instance.IsAllowRequestNotificationsPermission)
		{
			FirebaseMessaging.TokenReceived += OnTokenReceived;
			FirebaseMessaging.MessageReceived += OnMessageReceived;
			FirebaseMessaging.TokenRegistrationOnInitEnabled = true;
		}
	}
	else
	{
		// ...
	}
});

=======================================================================================

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:51 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
jmcgee412commented, Jul 21, 2022

I can confirm this issue is still present in 9.0.0, and it has now persisted for more than a year since 7.2.0

Also, the release notes for Version 8.2.0 still INCORRECTLY STATE that the Android issue of receiving tokens when initializing the app has been fixed

The issue is that on Android, the TokenRecieved delegate is only fired on the initial install. It never fires any time the app is run after the initial install. The issue also makes it so the Subscribe and Unsubscribe calls do not work. This issue is not present on iOS

The console log shows that the Subscribe or Unsubscribe task is called and just waits forever never receiving a response…and there is also incomplete information with above proposed workarounds I want to help with

Subscription task no response

GetTokenAsync() - Not a workaround GetTokenAsync() is not a workaround by itself. It will receive the current registration token, but it does nothing regarding whatever the connection issue is with the TokenReceived delegate and the Subscribe/Unsubscribe tasks. Those tasks are called and still just wait forever never receiving a response

DeleteTokenAsync() and GetTokenAsync() - Not a workaround This is also not a workaround by itself. If you call DeleteTokenAsync(), wait for it to complete, and then call GetTokenAsync(), it will fix the connection issue, refresh your registration token with a new one, and it will finally fire the TokenReceived delegate. However, all the subscriptions with the previous registration token will be lost

Workaround 1 - DeleteTokenAsync() and GetTokenAsync() and Re-subscribe One less than optimal workaround is to do this every time the client app is opened: Call DeleteTokenAsync(), wait for it to complete, then call GetTokenAsync, wait for it to complete, then re-subscribe to every topic. To prevent potential hanging issues with re-subscribing, you probably need to monitor each subscription task to wait for it to complete before calling the next one, which could take a bit of time if the client app has a lot of topics to subscribe to, all of which could delay the time before your app is ready for the user. This also means your app will need to monitor all subscribe and unsubscribe events to keep a locally held current list of active subscriptions so the client knows what to subscribe to on every use. And you need to hope your logic is sound because there’s no way using Unity SDKs for the client app to check in with FCM to confirm what topics it is subscribed to

Workaround 2 - Continue using Firebase 7.2.0 SDKs This is the second less than optimal workaround. This version works as intended for FCM (as far as I know) but you are missing out on the myriad of fixed crashes and bugs that have been worked on since that release. I can’t confirm how this will affect things like other packages that had more critical updates since then or having this work on Apple Silicon chips, etc.

My question to Google Firebase Developers Of these two less than optimal workarounds, which one would you say is the better option that has the least unintended consequences and trade-offs? Is it an issue that an app is deleting a token, re-registering, and re-subscribing to potentially thousands of topics every time the app is opened on every client?

…also, it might be helpful to put the workaround you suggest in the Unity Setup documentation or the Unity Troubleshooting notes, as the current notes have not led to a working solution for over a year, and seem to be causing hours and days of troubleshooting for developers until they stumble upon this

8reactions
cynthiajoancommented, Oct 4, 2021

Fixed in release 8.3.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolved - Firebase initializes, but no token received ...
I have a problem with Firebase Cloud Messaging (FCM). Everything used to work fine, but since recently my app doesn't receive tokens anymore....
Read more >
Set up a Firebase Cloud Messaging client app on Android
The user uninstalls/reinstall the app; The user clears app data. Apps still using deprecated Instance ID APIs for token management should update all...
Read more >
Remote Notifications with Firebase Cloud Messaging
This walkthrough provides a step-by-step explanation of how to use Firebase Cloud Messaging to implement remote notifications (also called ...
Read more >
Cloud Messaging
When an incoming message is "data-only" (contains no notification option), both Android & iOS regard it as low priority and will prevent the...
Read more >
Untitled
You can download the Firebase Unity SDK again at any time. ... Android Firebase 8.0.0 TokenReceived called only on ... - Github WebLeading...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found