firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
825 stars 428 forks source link

Android Firebase 8.0.0 TokenReceived called only on application reinstall #1088

Open maniaks1 opened 3 years ago

maniaks1 commented 3 years ago

[REQUIRED] Please fill in the following fields:

[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
    {
        // ...
    }
});

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

habitoti commented 1 year ago

Is Firebase even maintained still? Just updated from my old 7.2 Firebase version to 10.7 to try some of the latest desktop support beta stuff, just to find that this crucial feature is broken since ages. That's ridiculous...

TaejunPark commented 9 months ago

This is still happening on 11.6.0 I updated to the new version. I thought it sure is fixed as it was about 2 years ago and commented old dirty codes, but just not working 😇 I already spent another days to fix unity firebase-android plugin problem before this, and last week update just gone.

fb team all looking happy on youtube enjoying making their shit(= firebase for unity) long(=version ups for what?), like my AR book🤤

Nyankoo commented 9 months ago

@paulinon @chkuang-g @cynthiajoan A statement would be nice. It's unbelievable that this is still not fixed!

lsw1164 commented 9 months ago

Still not working...? I can't wait to work it.

FrantisekHolubec commented 4 months ago

Still problem on 11.9.0. anybody has some workaround for android and ios?

Gnejs commented 1 month ago

So here we are again, almost two years since I last commented, SDK 12.1.0 and this is still an issue.

To re-iterate, just calling GetTokenAsync() will not work, since it will only give you the token, the SDK is still broken and subscribing will NOT actually work.

Good news though, I did try the workaround suggested by [homu-konamilk] https://github.com/firebase/quickstart-unity/issues/1088#issuecomment-1308190083 and I can confirm that getting the token AND using the native java wrapper class does in fact work. This workaround seems much better than deleting the token and re-subscribing to all topics.

Makes you wonder how many Unity Android Apps have broken firebase integrations out there when everything seems fine first launch.

Anyway, hopefully someone finds this useful, try the aforementioned workaround. :)