addOnFailureListener无法在脱机模式下工作和网络问题 [英] addOnFailureListener not working in offline mode and network issues

查看:51
本文介绍了addOnFailureListener无法在脱机模式下工作和网络问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

addOnFailureListner不适用于add()数据,但addOnFailureListner不适用于get().

addOnFailureListner does not work for add() data, but addOnFailureListner works for get().

这不起作用

      WorkPlaceRef.add(DATA).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
            @Override
            public void onComplete(@NonNull Task<DocumentReference> task) {

                  //Successfully created - This one triggers when I turn on wifi again.

            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                // Error - This addonFailureListner is not working when there are no network.

            }
        });

此功能正常

      WorkPlaceRef.get().addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
            @Override
            public void onComplete(@NonNull Task<DocumentReference> task) {

                  //Successfully received - This one triggers when I turn on wifi again.

            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {

                // Error - this addonFialureListner triggers when there is no network.

            }
        });

推荐答案

在脱机状态下尝试写入数据并不是失败.Firestore SDK会将数据写入本地脱机缓存中首先,最终在应用程序重新联机时将其与服务器同步.每当发生这种情况时,都会调用成功侦听器.

It's not a failure to attempt to write data while offline. The Firestore SDK will write the data in a local offline cache first, and eventually synchronize that write with the server when the app comes back online. The success listener will be invoked whenever that happens.

仅当由于缺乏连通性而无法解决某些问题(例如违反安全规则)或超出某些已记录的

Write failures only happen when there is some problem that can't be retried due to lack of connectivity, such as security rule violations, or exceeding some documented limit of the database.

如果您想知道某些文档数据是否尚未与服务器同步,可以检查其

If you want to know if some document data is not yet synchronized with the server, you can check its metadata to know if a write is pending.

这篇关于addOnFailureListener无法在脱机模式下工作和网络问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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