I am using JSQMessagesViewController for sending and receiving messages.It works well for text Messages. Is it possible to send Text Message with attached Image File using JSQMessagesViewController Framework.
The attached image file should be shown, when it is clicked on. Something like this.
Send messages should be shown like this in Message window.
For Sending Photo
- (void)addPhotoMediaMessage
{
JSQPhotoMediaItem *photoItem = [[JSQPhotoMediaItem alloc] initWithImage:[UIImage imageNamed:@"goldengate"]];
JSQMessage *photoMessage = [JSQMessage messageWithSenderId:kJSQDemoAvatarIdSquires
displayName:kJSQDemoAvatarDisplayNameSquires
media:photoItem];
[self.messages addObject:photoMessage];
}
Sending text Message
- (void)didPressSendButton:(UIButton *)button
withMessageText:(NSString *)text
senderId:(NSString *)senderId
senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date
{
[JSQSystemSoundPlayer jsq_playMessageSentSound];
JSQMessage *message = [JSQMessage messageWithSenderId:senderId
displayName:senderDisplayName
text:text];
[self.messages addObject:message];
[self finishSendingMessageAnimated:YES];
[self receiveAutoMessage];
}
No it is not possible to send both as one message but you can send them as two messages with a unique custom identifier and then concat them together in your app.. Hope that help
To accomplish this task you will have to create a custom cell and then use that cell in your CollectionView
First of all subclass the JSQMessage class to something like following to keep the data for the image urls(attachments) -
Now you will have to use this class for all your chat messages.
Next, you will have to create a custom xib file for your custom cell. In that xib you will add a label and image view for the message text and attachment icon.
Now create a class representing your custom cell. It will be something as follows -
Now we have to use this CustomCell in our
JSQMessagesViewController
subclass.In
viewDidLoad
register your nib with the collection viewNow you can finally use your custom cell -
This should successfully render your custom cell.
Finally on tapping the custom view cell you can segue to a new VC (dont forget to pass your images data) and show the images appropriately.