Maliwan chat backed back-ended with Firebase.
- Typing indicator
- Photo messages
- Avatars as urls or as images
- Add
MTChat.framework
to the project.
* Make sure to mark "copy items if needed":
- Make sure you added the framework into "Embedded frameworks" section in "General" tab of the target.
- Subclass from main chat view controller:
@import MTChat;
@interface MyChatViewController : MTChatViewController {
}
@end
- Add the
chatDidLoad
andonError
handling block inside MyChatViewController.m:
#import "MyChatViewController.h"
@implementation MyChatViewController
- (void)viewDidLoad {
[super viewDidLoad];
//show spinner here
self.onChatDidLoad = ^{
//[weakSelf removeSpinner];
};
self.onError = ^(NSError *error) {
NSLog(@"Eror: %@", error.localizedDescription);
};
}
@end
- Instantiate your chat view controller and set display name and avatars:
MyChatViewController *chatViewController = [[MyChatViewController alloc] init];
chatViewController.senderDisplayName = @"User2";
chatViewController.channelId = @"hockey";
chatViewController.senderId = @"user2";
chatViewController.ownAvatarURL = @"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRE6Jn-YODWU_Ra92q8sEQdFdlB1D6FBePwNhr3PeCAgPzuZugt";
chatViewController.senderAvatarURL = @"https://images-na.ssl-images-amazon.com/images/M/MV5BNzQzNDMxMjQxNF5BMl5BanBnXkFtZTYwMTc5NTI2._V1_UY317_CR7,0,214,317_AL_.jpg";
[self.navigationController pushViewController:chatViewController animated:YES];
Channels
contain the list of channels. Messages
keep the conversation history. Appending new node in messages
will automatically result in new incoming message.
typingIndicator
node indicates the user typing the message at the moment. In the screenshot above typingIndicator
contains user2 : 1
. 1
is the integer value indicating the typing process. It means that user2 is typing message at the moment. If the typingIndicator
is empty it means that no one is typing the message at the moment.
There're two types of messages:
- Text message
- Photo message
It consists of:
senderId
. A simple unique id of the user who sent the message. Should not contain special symbols llike @, /, "", etc.senderName
. A name of the user that sent a message. It will show up visually in the chat.text
. Text of the message.
It consists of:
photoURL
. The url of to the photo in the Firebase Storate.senderId
. A simple unique id of the user who sent the message. Should not contain special symbols llike @, /, "", etc.
The storage persis all the images sent in chat. In this example the structure of the storage is the following:
Every user has its own foler in the root folder of the storage. Folder name is the user id and the filename of the picture inside that folder is just the time when user sent that picture.
Firebase.auth().currenuser().uid()/[timestamp].jpg