第二次加载应用程序时,Swift FireStore侦听器抛出错误

问题描述 投票:0回答:1

嗨,我迫切需要一些帮助

所有这些都发生在UIViewController子类中

我目前正在附加侦听器并填充数组,然后将其提供给以下函数中的UICollectionView(请原谅一些截断代码):

    fileprivate func fetchNotes() { // This function is called in vidDidLoad()
    let db = Firestore.firestore()
  // Attaching listener (ie. listener is an attribute of the class)
    listener = db.collection("Courses").document(titleForNavBar).collection("Notes")
        .addSnapshotListener { snapshot, error in
        // checking for any error
        if error != nil {
            self.arrayOfNotes.removeAll()
            self.allNotesView.arrayOfNotes = self.arrayOfNotes
            DispatchQueue.main.async {
                self.allNotesView.allNotesCollectionView.reloadData()
            }
            return
        } else {
            self.arrayOfNotes.removeAll()
            // if there is no error, the array holding all the objects is populated, in a for..loop
            for document in (snapshot?.documents)! {
            if let noteName = document.data()["noteName"] as? String,
               let lectureInformation = document.data()["lectureInformation"] as? String,
               let noteDescription = document.data()["noteDescription"] as? String,
               let forCourse = document.data()["forCourse"] as? String,
                    let storageReference = document.data()["storageReference"] as? String,
               let noteSize = document.data()["noteSize"] as? Int,
               let rating = document.data()["rating"] as? Int
                {
                    self.arrayOfNotes.append(Note(forCourse: forCourse, lectureInformation: lectureInformation, noteDescription: noteDescription, noteName: noteName, noteSize: noteSize, rating: rating, storageReference: storageReference))
                    self.allNotesView.arrayOfNotes = self.arrayOfNotes
                    // reloading the UICollectionView (on the main thread) so that it displays new data
                    DispatchQueue.main.async {
                       self.allNotesView.allNotesCollectionView.reloadData()
                    }
                }
            }

        }
    }
}

当视图消失时,我也删除了监听器

override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(true)
    if listener != nil {
    listener.remove()
    }
    print("listener removed")
} 

当我第一次在任何设备或模拟器上安装应用程序时,这很好用。当我尝试启动控制器时,第二次,我得到一个非常讨厌的错误,我不知道如何调试。

为了准确,控制台会抛出此错误:

NoteShare [97230:10528984] ***断言失败 - [FSTLevelDBRemoteDocumentCache decodingMaybeDocument:withKey:],third_party / firebase / ios / Source / Firestore / Source / Local / FSTLevelDBRemoteDocumentCache.mm:152

我知道这个问题很长(对不起),但你们有没有遇到过这个错误。请提供一些如何解决此问题的提示。谢谢!如果您需要查看我的任何其他代码,请告诉我。

ios swift firebase listener google-cloud-firestore
1个回答
0
投票

它似乎是失败的here。我没有看到你的代码中可能出错的原因,所以你可能遇到了一个错误。它似乎与this issue非常相似,qazxswpoi已在回购中修复但未被释放。

© www.soinside.com 2019 - 2024. All rights reserved.