gpt4 book ai didi

swift - JSQMessageAvatarImageFactory错误

转载 作者:行者123 更新时间:2023-11-30 12:49:46 24 4
gpt4 key购买 nike

由于某种原因,我遇到了崩溃,但我不知道为什么。一切都正确地从 FIRBase 中提取。但是当尝试加载用户 URL 时,我遇到了崩溃

打印(快照)

["MediaType": TEXT, "text": Test Message, "senderId": KG7b3tDTaoMwcAQAi2JI8vjj0OB2, "senderName": user1]
Optional({
email = "user1@gmail.com";
id = KG7b3tDTaoMwcAQAi2JI8vjj0OB2;
profileImage = "gs://big-pen.appspot.com/profileImage/KG7b3tDTaoMwcAQAi2JI8vjj0OB2";
username = user1;})

我的错误

fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)

这是我的代码。

func observeUsers(id: String){
FIRDatabase.database().reference().child("people").child(id).observeEventType(.Value, withBlock: { snapshot in
print(snapshot.value)
if let dict = snapshot.value as? [String: AnyObject] {
let avatarUrl = dict["profileImage"] as! String

//call the setupAvatar function
self.avatar(avatarUrl, messageId: id)

}
})
}


func avatar(url: String, messageId: String){

if DataService.dataService.currentUser != nil{
if url != "" {
let fileURL = NSURL(string: url )
let data = NSData(contentsOfURL: fileURL!)
let image = UIImage(data:data!) //<-----I am getting an error at this line error code: "Thread1:EXC_BAD_INSTRUCTION(code=Exc_I386_INVOP, subcode=0x0)"
let userImg = JSQMessagesAvatarImageFactory.avatarImageWithImage(image, diameter: 30)
avatarDict[messageId] = userImg
}else{
JSQMessagesAvatarImageFactory.avatarImageWithImage(UIImage(named: "cam_w.png"), diameter: 30)
}
collectionView.reloadData()
}
}

override func collectionView(collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageAvatarImageDataSource! {
let message = messages[indexPath.item]

return avatarDict[message.senderId]
//return JSQMessagesAvatarImageFactory.avatarImageWithImage(UIImage(named: "cam_w.png"), diameter: 30)
}

谢谢。我已经被这个问题困扰了两天了。

最佳答案

也许它不是一个有效的 URL,因此要检查它,请将您的头像功能更改为:

func avatar(url: String, messageId: String){

if DataService.dataService.currentUser != nil{
if let fileURL = NSURL(string: url ),
data = NSData(contentsOfURL: fileURL) {

let image = UIImage(data:data!) //<-----I am getting an error at this line error code: "Thread1:EXC_BAD_INSTRUCTION(code=Exc_I386_INVOP, subcode=0x0)"
let userImg = JSQMessagesAvatarImageFactory.avatarImageWithImage(image, diameter: 30)
avatarDict[messageId] = userImg
}else{
JSQMessagesAvatarImageFactory.avatarImageWithImage(UIImage(named: "cam_w.png"), diameter: 30)
}
collectionView.reloadData()
}
}

关于swift - JSQMessageAvatarImageFactory错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41147108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com