Search code examples
iosswiftjsqmessagesviewcontroller

JSQMessages: When I use photo messages my apps keeps crashing


I am building a chat app that is using JSQMessagesViewController to display images and Firebase as a backend.
The app is working without crashes when use text messages only, however when I add a photo message. The photo message is added to the collection view, however when I try to add a photo message, my app crashes on finishSendingMessage().

Please help :)

Function

Error

Console


Solution

  • I was going through a similar issue and none of the above answers helped. My issue was:

    -> media message added (worked fine) -> text message added just after media message (app crashed)

    I found that my problem lied in this piece of code in my cell for item at indexPath

        let message = messages[(indexPath as NSIndexPath).item]
        if message.senderId == senderId {
            cell.textView!.textColor = UIColor.white
        } else {
            cell.textView!.textColor = UIColor.black
        }
    

    I just commented out this code and everything works fine now.