I am using JSQMessage to create a chat application in Swift, basically my problem is when the user tap the photo I want the photo that is in the chat I want the photo to pop in fullscreen
I will add the steps of what I am trying to do it may be longer but easier to understand. (seems by the sender side, same is valid so the receiver as the image end up in the same array)
Sending the picture:
let sendMessage = JSQMessage(senderId: senderId, displayName: senderDisplayName, media: photoItem) <- Image I am interested is inside here
self.messages.append(sendMessage)
self.finishSendingMessage()
Great I can see the pic I sent on my screen and now I want to tap on it and I want it to popup full screen (for any of the old photos as well so I am using "didTapMessageBubbleAtIndexPath"
here I have println(messages[indexPath.row])
here retrieve my JSQMessage object for that message and I can see it has my image on it (as the dump in the end) but I cannot retrieve it.
My question is how can I retrieve this image so I can display it in full screen?
Thanks in advance
_isMediaMessage char '\x01' '\x01'
_senderId __NSCFString * "7CjXUi6426" 0x7874b730
_senderDisplayName __NSCFString * "Test3" 0x7874b8b0
_date __NSDate * 2015-07-27 13:28:46 UTC 0x78707d20
_text id 0x0 0x00000000
_media JSQPhotoMediaItem * 0x78725d90 0x78725d90
JSQMediaItem JSQMediaItem
NSObject NSObject
_appliesMediaViewMaskAsOutgoing BOOL YES '\x01'
_cachedPlaceholderView UIView * nil 0x00000000
**_image UIImage * 0x7887de40 0x7887de40**
NSObject NSObject
_imageRef __NSCFType * 0x78e67260 0x78e67260
_scale float 1 1
_traitCollection UITraitCollection * 0x78743a10 0x78743a10
_imageAsset UIImageAsset * nil 0x00000000
_cachedImageView UIImageView * 0x788b61a0 0x788b61a0
答案 0 :(得分:4)
看起来某人有一个类似的问题已被回答here。从本质上讲,您可以检查JSQMessage
对象是否附加了媒体,然后将其投射到JSQPhotoMediaItem
并从那里访问图像。
这是来自jessesquires的答案的Objective-C代码:
JSQMessage *message = [messages objectAtIndex:indexPath.row];
if (message.isMediaMessage) {
id<JSQMessageMediaData> mediaItem = message.media;
if ([mediaItem isKindOfClass:[JSQPhotoMediaItem class]]) {
JSQPhotoMediaItem *photoItem = (JSQPhotoMediaItem *)mediaItem;
UIImage *image = photoItem.image;
// do stuff with the image
}
}
答案 1 :(得分:0)
Swift 3
let message = self.messages[indexPath.row]
if message.isMediaMessage == true{
let mediaItem = message.media
if mediaItem is JSQPhotoMediaItem{
let photoItem = mediaItem as! JSQPhotoMediaItem
let image:UIImage = photoItem.image //UIImage obtained.
}
}