1. <legend id='SGEdi'><style id='SGEdi'><dir id='SGEdi'><q id='SGEdi'></q></dir></style></legend>
    <tfoot id='SGEdi'></tfoot>

    <i id='SGEdi'><tr id='SGEdi'><dt id='SGEdi'><q id='SGEdi'><span id='SGEdi'><b id='SGEdi'><form id='SGEdi'><ins id='SGEdi'></ins><ul id='SGEdi'></ul><sub id='SGEdi'></sub></form><legend id='SGEdi'></legend><bdo id='SGEdi'><pre id='SGEdi'><center id='SGEdi'></center></pre></bdo></b><th id='SGEdi'></th></span></q></dt></tr></i><div id='SGEdi'><tfoot id='SGEdi'></tfoot><dl id='SGEdi'><fieldset id='SGEdi'></fieldset></dl></div>

    • <bdo id='SGEdi'></bdo><ul id='SGEdi'></ul>
    1. <small id='SGEdi'></small><noframes id='SGEdi'>

      FCM:onNewToken 与 FirebaseInstanceId

      时间:2023-07-29
        <bdo id='WH7js'></bdo><ul id='WH7js'></ul>

          <small id='WH7js'></small><noframes id='WH7js'>

            <tbody id='WH7js'></tbody>
          1. <tfoot id='WH7js'></tfoot>

              <i id='WH7js'><tr id='WH7js'><dt id='WH7js'><q id='WH7js'><span id='WH7js'><b id='WH7js'><form id='WH7js'><ins id='WH7js'></ins><ul id='WH7js'></ul><sub id='WH7js'></sub></form><legend id='WH7js'></legend><bdo id='WH7js'><pre id='WH7js'><center id='WH7js'></center></pre></bdo></b><th id='WH7js'></th></span></q></dt></tr></i><div id='WH7js'><tfoot id='WH7js'></tfoot><dl id='WH7js'><fieldset id='WH7js'></fieldset></dl></div>

                <legend id='WH7js'><style id='WH7js'><dir id='WH7js'><q id='WH7js'></q></dir></style></legend>
              1. 本文介绍了FCM:onNewToken 与 FirebaseInstanceId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Firebase 已弃用 com.google.firebase:firebase-messaging:17.1.0 版本中的一些消息调用.post 很好地介绍了这些更改.

                Firebase has deprecated some of the messaging calls in the com.google.firebase:firebase-messaging:17.1.0 release. This post goes over those changes nicely.

                问题:有人能告诉我不实现 onNewToken 是否被认为是不好的做法,而是在每次应用启动时调用下面的块 这对于 Android 人来说可能似乎过分了但从 iOS 的角度来看,感觉就像家一样.

                Question: Can someone tell me if is it considered bad practice to not implement onNewToken and instead just call the below block each app launch This probably seems excessive to Android folks but feels like home from an iOS point of view.

                FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener(this) { instanceIdResult ->
                    // Just use this call 
                    val newToken = instanceIdResult.token
                    Log.i("newToken", newToken)
                }
                
                
                
                @Override
                public void onNewToken(String s) {
                    super.onNewToken(s);
                    // Leave this unimplemented
                }
                

                我更熟悉 iOS,它在 每个 应用程序启动时调用其 onNewToken 等效项.所以对于 iOS,我把逻辑放在那里以确定我的后端是否需要更新.

                I am more familiar with iOS which calls its onNewToken equivalent on every app launch. So for iOS I put logic there to determine if my backend needs to be updated.

                getInstanceId() 文档说 如果它尚不存在,则会生成一个实例 ID,它会开始定期向 Firebase 后端发送信息.这让我假设我可以在每次启动时调用 FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener.

                getInstanceId() docs say This generates an Instance ID if it does not exist yet, which starts periodically sending information to the Firebase backend. This makes me assume I can just call FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener each launch.

                推荐答案

                有些事情非常很重要,但还没有人提到:

                Something very important that no one has mentioned yet:

                如果您仅在应用启动后检查当前设备令牌,您可能会在应用处于后台时丢失令牌更新事件(当然),并且您将无法接收远程推送消息从您的服务器直到用户再次启动应用程序并将新令牌发送到服务器.

                If you check for the current device token only after an app launch, you might loose the event of the token being updated while your app is in the background (of course) and you won't be able to receive remote push messages from your server until the user launches the app again and you send the new token to the server.

                在您的应用程序处于后台时也可以调用该回调的全部目的是防止丢失后端消息(如果您的应用程序或其某些重要功能在很大程度上依赖于推送通知,这一点很重要).请务必注意,此回调不仅会在您首次注册设备时为您提供令牌,而且 also: 如果 InstanceID 令牌更新则调用.如果先前令牌的安全性受到威胁,则可能会发生这种情况.

                The whole purpose of having that callback which can also be called while your app is in the background is to prevent loosing backend messages (important if your app or some important features of it relies a lot on push notifications). It is important to be aware that this callback will not only deliver you the token when you register the device for the first time but also: Called if InstanceID token is updated. This may occur if the security of the previous token had been compromised.

                所以:

                谁能告诉我不实现 onNewToken 而是在每个应用程序启动时调用下面的块是否被认为是不好的做法这对 Android 人来说可能看起来有点过分,但从 iOS 的角度来看就像家一样.

                Can someone tell me if is it considered bad practice to not implement onNewToken and instead just call the below block each app launch This probably seems excessive to Android folks but feels like home from an iOS point of view.

                是的,不实现 onNewToken() 实际上是一种不好的做法.

                Yes, it is actually a bad practice to not implement onNewToken().

                这篇关于FCM:onNewToken 与 FirebaseInstanceId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:iOS 14 上的颤振 FCM 7 下一篇:证书有效时 InvalidApnsCredential

                相关文章

              2. <i id='ES3x0'><tr id='ES3x0'><dt id='ES3x0'><q id='ES3x0'><span id='ES3x0'><b id='ES3x0'><form id='ES3x0'><ins id='ES3x0'></ins><ul id='ES3x0'></ul><sub id='ES3x0'></sub></form><legend id='ES3x0'></legend><bdo id='ES3x0'><pre id='ES3x0'><center id='ES3x0'></center></pre></bdo></b><th id='ES3x0'></th></span></q></dt></tr></i><div id='ES3x0'><tfoot id='ES3x0'></tfoot><dl id='ES3x0'><fieldset id='ES3x0'></fieldset></dl></div>

                <small id='ES3x0'></small><noframes id='ES3x0'>

                1. <legend id='ES3x0'><style id='ES3x0'><dir id='ES3x0'><q id='ES3x0'></q></dir></style></legend>

                      <bdo id='ES3x0'></bdo><ul id='ES3x0'></ul>
                  1. <tfoot id='ES3x0'></tfoot>