ios - Firebase 快速返回 incored 快照

标签 ios swift firebase firebase-realtime-database

我有一个 firebase 聊天应用程序,我正在尝试获取用户凭据,但我在控制台中从 firebase 获取了错误的值

enter image description here

这就是我的引用和快照,当我决定在控制台中打印它时,我得到了它

CREDENTiL data ref Optional({
    "cc71128f-99a7-4435-879b-b1d0c7ce9c37" =     {
        location = "-Lav1QzhaoRMGAJHy8nQ";
    };
})
CREDENTiL data ref Optional({
    email = "adie.olalekan@max.ng";
    name = "Olalekan Adie";
    profilePicLink = "http://www.freeiconspng.com/uploads/profile-icon-9.png";
})

这是我的代码

self.allUserRef?.observe(.childAdded, with: { (snapshot) in
                let id = snapshot.key
                print("CREDENTiL data ref \(snapshot.value)")

                if let data = snapshot.value as? [String: AnyObject] {
                    if snapshot.hasChild("credentials") {
                    print("CREDENTiL data \(data)")
                        if let credentials = data["credentials"]! as? [String: AnyObject] {
                            print("CREDENTiL \(credentials)")
                            if id != exceptID {
                                let userInfo = ChatUser(dictionary: data as NSDictionary)
                            }
                        }
                    }
                }
            })

任何帮助将不胜感激

最佳答案

let refer = Database.database().reference()

refer.child("chatUsers").child("your uid").observe(.childAdded, with: { (snapshot) in
            let id = snapshot.value//your snapshot
            if((((snapshot.value as! NSDictionary).allKeys) as! NSArray).contains("credentials"))
            {
                print("credentials",snapshot.value)
            }
        })

请尝试上面的代码以获取您的凭据作为快照。

关于ios - Firebase 快速返回 incored 快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55373414/

相关文章:

iphone - CLLocationManager 从不调用委托(delegate)方法

swift - 正确编写我的文件,以便在未安装我的应用程序时它们可以作为文本打开

javascript - 为什么 $firebaseSimpleLogin :logout event execute an alert() more than once?

iOS - 在多个线程上处理照片

ios - 如何使用 RxDatasource 在具有多个 header 的 UICollectionView 中创建多个部分

iphone - @2x 和图像分辨率的混淆

ios - UICollectionViewFlowLayout,UICollectionView : changing screen orientation breaks cells arrangement

swift - swift mapview等待数据库

android - 使用 Firebase Analytics for mobile app(iOS 和 Android)进行事件日志和比较

android - 更新到 Android studio 3.5 后出现以下错误 - FAILURE : Build failed with an exception