Firebase中的未注册注册令牌

问题描述:

即使我确定自己的令牌正确无误,也得到了未注册的注册令牌,并且我正在使用主令牌FirebaseInstanceId.Instance.Token在我的日志中对其进行检查.

I got unregistered registration token even I am sure my token is correct and I check it in my log I am using master token FirebaseInstanceId.Instance.Token.

这是我的方法:

private void ConfigureFireBase()
        {

            Task.Run(() => {
                var instanceId = FirebaseInstanceId.Instance;
                Android.Util.Log.Debug("TAG", "{0} {1}", instanceId?.Token?.ToString(), instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));

            });

        }

我也检查OnTokenRefresh方法相同的令牌

I check as well OnTokenRefresh method the same token

public override void OnTokenRefresh()
        {
            var refreshedToken = FirebaseInstanceId.Instance.Token;
            Log.Debug(TAG, "Refreshed token: " + refreshedToken);
            SendRegistrationToServer(refreshedToken);
        }

但是当我在Firebase控制台中尝试时,当我在 http://pushtry.com/使用相同的令牌但没有收到 NotRegistered 消息

but when I tried in Firebase console it gives me this error message, when I tried in http://pushtry.com/ with the same token I got not NotRegistered message

注意 ,当我卸载该应用程序并再次安装该令牌时,但是一段时间后却收到此错误消息.

Note when I uninstall the app and install again the token working, but after while I got this error message.

引发此问题的原因导致令牌未注册

The reason why this issue fired cause that token is unregistered

The registration token may change when:

The app deletes Instance ID
The app is restored on a new device
The user uninstalls/reinstall the app
The user clears app data.

参考

而且这仅在调试模式下发生,所以请不要担心在发布模式下一切都会好起来的.

and this happen in debug mode only so dont worry in release mode every thing will be fine.

如何解决此问题?

在登陆活动(MainActivity,Login)中,只需强制刷新令牌即可调用此方法,此方法可强制firebase调用OnTokenRefresh()

its easy just force to refresh token call this method in your landing activity (MainActivity , Login ) , this method force firebase to call OnTokenRefresh()

private void ConfigureFireBase()
        {

#if DEBUG

            Task.Run(() =>
            {
                var instanceId = FirebaseInstanceId.Instance;
                instanceId.DeleteInstanceId();
                Android.Util.Log.Debug("TAG", "{0} {1}", instanceId?.Token?.ToString(), instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));

            });

            // For debug mode only - will accept the HTTPS certificate of Test/Dev server, as the HTTPS certificate is invalid /not trusted
            ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;


#endif
        }

希望这对任何遇到相同问题的人都有帮助

Hope this help any one face same issue