【发布时间】:2017-09-19 14:48:08
【问题描述】:
您好,我正在使用 Firebase 和 Swift3 构建我的应用程序,但是当我运行代码时出现此错误 "(child:) Must be a non-empty string and not contain '.' '#' '$' '[' 或 ']''" 。这是我得到错误的函数,即使一切正常
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 时,它会返回正确的值。我还更新了 pod,但没有解决任何问题。 在此先感谢:)
解决方案:错误是我在 ChatLogController 的 viewDidLoad 中插入了一个 func,当用户决定结束聊天时,另一个人会收到通知,但该 func 需要另一个用户 Uid 并且当视图加载时不是任何uid,因为它必须被传递,所以我在“viewDidAppear”中插入了func,一切正常。感谢所有试图帮助我的人。
【问题讨论】:
-
请显示firebase数据json