Cloud Firestore.getDocuments回调在Swift5上不起作用

Cloud Firestore.getDocuments回调在Swift5上不起作用,swift,google-cloud-firestore,ios13,Swift,Google Cloud Firestore,Ios13,我目前正在使用Swift5构建一个iOS13应用程序。 我使用的数据库是CloudFireStore。以下链接是我当前收藏的图像。 我也在使用FirebaseAuth 我的目标:当应用程序终止时,从用户当前参与的所有文件室中删除当前登录的用户。使用.whereField(“参与者”,arrayContains:displayName)查找所有文档(也称为“文件室”),并从每个参与的“文件室”参与者数组中删除当前用户的显示名 当前状态和问题:我的代码如下所示。当我终止我的应用程序时,print(

我目前正在使用Swift5构建一个iOS13应用程序。 我使用的数据库是CloudFireStore。以下链接是我当前收藏的图像。

我也在使用FirebaseAuth

我的目标:当应用程序终止时,从用户当前参与的所有文件室中删除当前登录的用户。使用
.whereField(“参与者”,arrayContains:displayName)
查找所有文档(也称为“文件室”),并从每个参与的“文件室”参与者
数组中删除当前用户的显示名

当前状态和问题:我的代码如下所示。当我终止我的应用程序时,
print(“displayName”)
会打印到控制台,但是
db.collection(“房间”)
中的所有代码似乎都没有响应<代码>打印(“Hello World!”)
数据库集合(“房间”)的内部。回调不会与其他回调代码一起打印到控制台。我不太清楚为什么
db.collection(“房间”)
回调无法正常工作

    func applicationWillTerminate(_ application: UIApplication) {
        let db = Firestore.firestore()

        if let currentUser = Auth.auth().currentUser {
    
            let displayName = currentUser.displayName!
            
            print("displayName")    // This prints
            
            db.collection("rooms").whereField("participants", arrayContains: displayName)
                .getDocuments { (querySnapshot, error) in
    
                    print("Hello World!") // This does not print, and the code below doesn't seem to respond
                    
                    if let e = error {
                        print (e.localizedDescription)
                    } else {
                        if let snapshotDocuments = querySnapshot?.documents {
                            for doc in snapshotDocuments {
                                let data = doc.data()
                                print(data)
                            }
                        }
                    }
                } // db.collection("rooms")
            } else {
                print("No Current User Signed In")  // This does not print
            }
        print ("End of applicationWillTerminate")   // This prints
    }

根据“此方法的实现有大约五秒钟的时间来执行任何任务并返回。如果该方法在时间到期之前未返回,系统可能会完全终止该进程。”您是否计算了您的操作在
应用程序将终止
之外所需的时间,以确保它满足此要求?@FrankvanPuffelen非常感谢您让我知道这一点。我会尽力让你知道的。