Terminating app due to uncaught exception 'InvalidpathValIDation',reason: '(child:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']''
我不知道是什么导致了这一点.用户的userID在登录时会打印到控制台,但是一旦按下登录按钮,我的应用程序就会崩溃.在我更新到Swift 3之前,这个错误是不存在的,实际上只有在我修复了应用程序的另一部分中的错误之后才出现.
无论如何,我的应用程序中只有两个主要类:LoginVIEwController和ChatVIEwController.
这是LoginVIEwController的代码:
import UIKitimport Firebaseclass LoginVIEwController: UIVIEwController { // MARK: PropertIEs var ref: FIRDatabaseReference! // 1 var userID: String = "" overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() ref = FIRDatabase.database().reference() // 2 } @IBAction func loginDIDtouch(_ sender: AnyObject) { FIRAuth.auth()?.signInAnonymously() { (user,error) in if let user = user { print("User is signed in with uID: ",user.uID) self.userID = user.uID } else { print("No user is signed in.") } self.performSegue(withIDentifIEr: "Logintochat",sender: nil) } } overrIDe func prepare(for segue: UIStoryboardSegue,sender: AnyObject?) { super.prepare(for: segue,sender: sender) let navVc = segue.destinationVIEwController as! UINavigationController // 1 let chatVc = navVc.vIEwControllers.first as! ChatVIEwController // 2 chatVc.senderID = userID // 3 chatVc.senderdisplayname = "" // 4 }}
这是我的ChatVIEwController代码:
import UIKitimport Firebaseimport JsQMessagesVIEwControllerclass ChatVIEwController: JsQMessagesVIEwController { // MARK: PropertIEs var rootRef = FIRDatabase.database().reference() var messageRef: FIRDatabaseReference! var messages = [JsQMessage]() var outgoingBubbleImageVIEw: JsQMessagesBubbleImage! var incomingBubbleImageVIEw: JsQMessagesBubbleImage! var userIsTyPingRef: FIRDatabaseReference! // 1 private var localTyPing = false // 2 var isTyPing: Bool { get { return localTyPing } set { // 3 localTyPing = newValue userIsTyPingRef.setValue(newValue) } } var usersTyPingquery: FIRDatabasequery! overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() Title = "ChatChat" setupBubbles() // No avatars collectionVIEw!.collectionVIEwLayout.incomingAvatarVIEwSize = CGSize.zero collectionVIEw!.collectionVIEwLayout.outgoingAvatarVIEwSize = CGSize.zero messageRef = rootRef.child("messages") } overrIDe func vIEwDIDAppear(_ animated: Bool) { super.vIEwDIDAppear(animated) observeMessages() observeTyPing() } overrIDe func vIEwDIDdisappear(_ animated: Bool) { super.vIEwDIDdisappear(animated) } func collectionVIEw(collectionVIEw: JsQMessagesCollectionVIEw!,messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JsQMessageData! { return messages[indexPath.item] } func collectionVIEw(collectionVIEw: JsQMessagesCollectionVIEw!,messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JsQMessageBubbleImageDataSource! { let message = messages[indexPath.item] // 1 if message.senderID == senderID { // 2 return outgoingBubbleImageVIEw } else { // 3 return incomingBubbleImageVIEw } } overrIDe func collectionVIEw(_ collectionVIEw: UICollectionVIEw,numberOfItemsInSection section: Int) -> Int { return messages.count } func collectionVIEw(collectionVIEw: JsQMessagesCollectionVIEw!,avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JsQMessageAvatarImageDataSource! { return nil } private func setupBubbles() { let factory = JsQMessagesBubbleImageFactory() outgoingBubbleImageVIEw = factory?.outgoingMessagesBubbleImage( with: UIcolor.Jsq_messageBubbleBlue()) incomingBubbleImageVIEw = factory?.incomingMessagesBubbleImage( with: UIcolor.Jsq_messageBubblelightGray()) } func addMessage(ID: String,text: String) { let message = JsQMessage(senderID: ID,displayname: "",text: text) messages.append(message!) } overrIDe func collectionVIEw(_ collectionVIEw: UICollectionVIEw,cellForItemAt indexPath: IndexPath) -> UICollectionVIEwCell{ let cell = super.collectionVIEw(collectionVIEw,cellForItemAt: indexPath) as! JsQMessagesCollectionVIEwCell let message = messages[indexPath.item] if message.senderID == senderID { cell.textVIEw!.textcolor = UIcolor.white() } else { cell.textVIEw!.textcolor = UIcolor.black() } return cell } func dIDPressSendbutton(button: UIbutton!,withMessageText text: String!,senderID: String!,senderdisplayname: String!,date: NSDate!) { let itemRef = messageRef.childByautoID() // 1 let messageItem = [ // 2 "text": text,"senderID": senderID ] itemRef.setValue(messageItem as? AnyObject) // 3 // 4 JsQSystemSoundplayer.Jsq_playMessageSentSound() // 5 finishSendingMessage() isTyPing = false } private func observeMessages() { // 1 let messagesquery = messageRef.querylimited(tolast: 25) // 2 messagesquery.observe(.childAdded) { (snapshot: FIRDataSnapshot!) in // 3 let ID = snapshot.value!["senderID"] as! String let text = snapshot.value!["text"] as! String // 4 self.addMessage(ID: ID,text: text) // 5 self.finishReceivingMessage() } } private func observeTyPing() { let tyPingIndicatorRef = rootRef.child("tyPingIndicator") userIsTyPingRef = tyPingIndicatorRef.child(senderID) userIsTyPingRef.ondisconnectRemoveValue() // 1 usersTyPingquery = tyPingIndicatorRef.queryOrderedByValue().queryEqual(tovalue: true) // 2 usersTyPingquery.observe(.value) { (data: FIRDataSnapshot!) in // 3 You're the only tyPing,don't show the indicator if data.childrenCount == 1 && self.isTyPing { return } // 4 Are there others tyPing? self.showTyPingIndicator = data.childrenCount > 0 self.scrollToBottom(animated: true) } } overrIDe func textVIEwDIDChange(_ textVIEw: UITextVIEw) { super.textVIEwDIDChange(textVIEw) // If the text is not empty,the user is tyPing isTyPing = textVIEw.text != "" } func collectionVIEw(collectionVIEw: JsQMessagesCollectionVIEw!,attributedTextForCellBottomLabelAtIndexPath indexPath: NSIndexPath!) -> AttributedString! { return AttributedString(string:"test") }}
记住,所有这些代码都是用Swift 3编写的.
如果您能找到任何可以帮助我解决问题并最终让我的应用程序运行的东西,我将成为您最好的朋友.
提前致谢!
解决方法 Swift 3.0是目前处于测试阶段的开发者版本,预计将于2016年底发布.有些库可能尚未提供,或者可能包含错误,因此您应该立即重新安装最新的Swift公共稳定版本(目前编写v2.2).
您自己说您已更新为Xcode的测试版.因此,我建议您通过重新下载Xcode from the Mac App Store并删除Xcode的测试版来重新安装Swift 2.2.
对于Swift 3,请等到Apple在2016年秋季发布公开版本.然后,查看您的代码是否有效.
Firebase可能尚未更新其Swift 3.0库.
在此之前,我建议你继续使用Swift 2.2.由于兼容性错误,您不希望您的应用突然停止工作.
你说你下载了Xcode的beta版.我至少会等待Apple在2016年秋季发布Xcode的公开版本,然后再次尝试使用您的代码.
但是,我们不知道Firebase何时会更新其库.保留代码备份,并在备用机器中下载更新版本的Xcode.如果您的代码在备用计算机中正常运行,请在主计算机中下载.或者,安装一个虚拟机,如VirtualBox,然后在那里试用你的应用程序.
总结以上是内存溢出为你收集整理的ios – 使用Swift 3时的’InvalidPathValidation’全部内容,希望文章能够帮你解决ios – 使用Swift 3时的’InvalidPathValidation’所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)