首页 文章

(child :)必须是非空字符串且不包含'.' '#' '$' '['或']''

提问于
浏览
1

嗨,我正在使用Firebase和Swift3构建我的应用程序,但是当我运行代码时出现此错误“(child :)必须是非空字符串且不包含' . ' '#''$''['或']''' . 这是我得到错误的函数,即使一切都应该工作

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    print (self.otherUserUid)
    let reference = Database.database().reference().child("User-messages").child(Auth.auth().currentUser!.uid).child(self.otherUserUid).queryLimited(toLast: 51)
    reference.observeSingleEvent(of: .value, with: {[weak self] (snapshot) in
        print("IN")
        let messages = Array(JSON(snapshot.value as Any).dictionaryValue.values).sorted(by: { (lhs, rhs) -> Bool in
            return lhs["date"].doubleValue < rhs["date"].doubleValue

        })
        let converted = self!.convertToChatItemProtocol(messages: messages)
        if converted.isEmpty == true {
            print ("empty")
        }
        let navcontroller = segue.destination as! UINavigationController
        let chatlog = navcontroller.topViewController as! ChatLogController
        chatlog.userUID = self.otherUserUid
        chatlog.dataSource = DataSource(initialMessages: converted ,uid: (self?.UIDLabel.text)!)
        chatlog.MessagesArray = FUIArray(query: Database.database().reference().child("User-messages").child(Me.uid).child((self?.UIDLabel.text)!).queryStarting(atValue: nil, childKey: converted.last?.uid), delegate: nil)


        messages.filter({ (message) -> Bool in
            return message["type"].stringValue == PhotoModel.chatItemType
        }).forEach({ (message) in
            self?.parseURLs(UID_URL: (key: message["uid"].stringValue, value: message["image"].stringValue))
        })

    })

}

应用程序在打印“IN”之前崩溃,但是当我打印self.otherUserUid时,它返回正确的值 . 我也更新了 beans 荚,但它没有解决任何问题 . 提前致谢 :)

解决方案:错误是我在ChatLogController的viewDidLoad中插入了一个func,当用户决定结束聊天时,另一个获取信息,但该func需要其他用户Uid,而当视图加载时则没有任何uid因为必须传递,所以我在“viewDidAppear”中插入了func,一切正常 . 感谢所有试图帮助我的人 .

1 回答

  • 0

    发生这种情况是因为这个符号 '.' '#' '$' '[' or ']' 在Firebase中是禁止的 . Firebase中的密钥不能包含任何此符号 . 因此,为了解决这个问题,您需要通过将这些符号替换为允许的其他符号来对这些字符串进行编码 . 例如,对于我重新发送的电子邮件地址,您可以进行此更改 .

    name@email.com - > name @ email,com

    正如您可能看到的那样,我用 , (逗号)替换了 . (点) .

相关问题