1

Im building a small chat app using JSQMessages, and trying to send images from photo library or camera.

I got to the point where I saved the image to parse backend but I cannot display it on screen. I found few solutions but they were in obj-C, I tried to swift-fy but it failed.

I have extra column in parse "images" next to "message".

Here is what I tried:

var message = messages[indexPath.row]
if message != "" {
  return messages[indexPath.row]
} else if message?.isMediaMessage == true {
  let mediaItem:JSQMessageMediaData = message!.media
  if (mediaItem.isKindOfClass(JSQPhotoMediaItem)) {
    var photoItem: JSQPhotoMediaItem = mediaItem as! JSQPhotoMediaItem
    var image: UIImage = photoItem.image
    print("yay")
  }
}
return messages[indexPath.row]
vard
  • 4,057
  • 2
  • 26
  • 46
Terry
  • 107
  • 2
  • 11

1 Answers1

0

You are not actually setting the message content to the photo that you have saved on the backend. You have a var image: UIImage = photoItem.image that just saves it to a variable not to the message content that is being displayed. Also this does evaluate if (mediaItem.isKindOfClass(JSQPhotoMediaItem)) { var photoItem: JSQPhotoMediaItem = mediaItem as! JSQPhotoMediaItem

so if set your message.media = (data from parse) it should show up.

Dan Leonard
  • 3,325
  • 1
  • 20
  • 32
  • Thanks for the info. as i mentioned, thats what i have tried. i know its not working :( having difficulties understanding you though. as you said.(mediaItem.isKindOfClass(JSQPhotoMediaItem)) { var photoItem: JSQPhotoMediaItem = mediaItem as! JSQPhotoMediaItem part. am i on the write track? beside displaying the picture on UIImage? – Terry Feb 16 '16 at 06:40
  • I would say ya your on the right track but wont know till your displaying in message bubbles. – Dan Leonard Feb 16 '16 at 16:55