即使我确定我的 token 是正确的,我也得到了未注册的注册 token ,我在我的日志中检查它我正在使用主 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
方法相同的 token
public override void OnTokenRefresh()
{
var refreshedToken = FirebaseInstanceId.Instance.Token;
Log.Debug(TAG, "Refreshed token: " + refreshedToken);
SendRegistrationToServer(refreshedToken);
}
但是当我在 Firebase 控制台中尝试时,它给了我这个错误消息,当我在 http://pushtry.com/ 中尝试时同理,我没有收到 NotRegistered 消息
注意当我卸载应用程序并再次安装 token 工作时,但之后我收到此错误消息。
最佳答案
此问题触发的原因是 token 未注册
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.
这只会在 Debug模式下发生,所以不用担心在 Release模式下一切都会好起来的。
如何解决此问题?
它很容易在你的登陆 Activity (MainActivity,Login)中强制刷新 token 调用这个方法,这个方法强制firebase调用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
}
希望这可以帮助任何面临同样问题的人
关于android - Firebase 中未注册的注册 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42537072/