Firestore由于客户端处于脱机状态而无法获取文档

时间:2018-09-20 18:40:51

标签: android google-cloud-firestore

嗨,大家好,我是Firebase-Firestore的新手,离线时遇到错误。
我已经将Persistence设置为(True)并在脱机时获取一些缓存的数据,但是有一个函数使我出现此脱机错误,logcat将我指向(task.getResult()。exists())。我不知道该怎么办,有人可以帮我吗?谢谢。

错误: com.google.android.gms.tasks.RuntimeExecutionException:com.google.firebase.firestore.FirebaseFirestoreException:由于客户端处于离线状态而无法获取文档。

firebaseFirestore.collection("Posts/" + blogPostId + "/Likes").document(currentUserId).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                @Override
                public void onComplete(@NonNull Task<DocumentSnapshot> task) {

                    if(!task.getResult().exists()){ //I GET ERROR HERE

                        Map<String, Object> likesMap = new HashMap<>();
                        likesMap.put("timestamp", FieldValue.serverTimestamp());

                        firebaseFirestore.collection("Posts/" + blogPostId + "/Likes").document(currentUserId).set(likesMap);

                    } else {

                        firebaseFirestore.collection("Posts/" + blogPostId + "/Likes").document(currentUserId).delete();

                    }

                }
            });

1 个答案:

答案 0 :(得分:0)

对于我在 flutter android app 开发过程中

  • 打开 android studio 模拟器 并选择擦除数据
  • 然后再次运行

注意:我只知道安卓。