Firebase 中未注册的注册令牌 [英] Unregistered Registration Token in Firebase

查看:36
本文介绍了Firebase 中未注册的注册令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了未注册的注册令牌,即使我确定我的令牌是正确的,我在我的日志中检查它我使用的是主令牌 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 方法相同的令牌

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

但是当我在 Firebase 控制台中尝试时它给了我这个错误信息,当我在 http://pushtry.com/ 同理,我没有收到 NotRegistered 消息

注意当我卸载应用程序并再次安装令牌时,令牌工作正常,但之后我收到此错误消息.

解决方案

触发此问题的原因是 token 未注册

<块引用>

注册令牌可能会在以下情况下更改:应用程序删除实例 ID该应用程序已在新设备上恢复用户卸载/重新安装应用程序用户清除应用数据.

参考

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

如何解决问题?

它很容易只是强制刷新令牌在您的登陆活动 (MainActivity , Login ) 中调用此方法,此方法强制 firebase 调用 OnTokenRefresh()

private void ConfigureFireBase(){#if 调试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));});//仅用于调试模式 - 将接受测试/开发服务器的 HTTPS 证书,因为 HTTPS 证书无效/不可信ServicePointManager.ServerCertificateValidationCallback +=(o,证书,链,错误)=>真的;#万一}

希望对遇到同样问题的朋友有所帮助

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.

Here is my method:

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));

            });

        }

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);
        }

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.

Reference

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

How you can fix the issue ?

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

这篇关于Firebase 中未注册的注册令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆