为什么更新数据后总是在Firestore中触发我的getDocument方法?

时间:2018-08-15 11:39:47

标签: ios swift firebase google-cloud-firestore

我在UserKM类中有一个方法声明,例如以下代码:

static func getUserData (userID: String, completion: @escaping (UserKM?)->Void) {

        FirestoreDocumentReference.users(uidUser: userID).reference().getDocument { (snapshot, error) in
            if let error = error {
                print("Failed to get the user data: \(error.localizedDescription)")
                completion(nil)
            } else {
                print("Successfully get the user data from Firestore")

                guard let docSnaphot = snapshot, docSnaphot.exists else {
                    completion(nil)
                    return
                }

                guard let myUserData = docSnaphot.data() else {return}
                let user = UserKM(dictionary: myUserData)
                completion(user)

            }
        }

    }

,该getUserData方法将在视图控制器的下面函数UserKM.getUserData中使用

func getUserKMData() {

        userData = Auth.auth().currentUser
        guard let userID = userData?.uid else {return}

        SVProgressHUD.show(withStatus: "Harap Tunggu")



        UserKM.getUserData(userID: userID) { (userKumpMuslim) in

            guard let userKumus = userKumpMuslim else {return}
            self.userKumpulMuslim = userKumus
            self.setDomicileButton()
            userKumus.saveUserKMBasicDataToKeychain()

            self.hasBeenFetchedMoreThan24HoursAgo = self.checkIfItHasBeenFetchedForTheLast24HoursOrNot()

            if self.hasBeenFetchedMoreThan24HoursAgo {
                self.getRecommendedEvents()
            } else {
                self.readRecommendedEventsInUserDefault()
            }


        }



    }

但是我不明白为什么无论何时更新用户数据,总是会自动触发该UserKM.getUserData方法。

我没有使用侦听器,但似乎这种行为类似于使用.addSnapshotListener,但是我在这里使用.getDocument

如何使其不自动触发?

0 个答案:

没有答案