I am trying to share image/video in chat module. I've referred Sample code for this but couldn't find any help.
Alos I've referred http://quickblox.com/modules/chat/ it says Add live chat functions to your app by plugging in our full featured chat module. Fast, Firewall friendly, Robust & Secure. Does it means I have to purchase full featured chat module ?
Please suggest me the right way.
Thanks
Yes, QuickBlox Chat allows to share files, video/audio between 2 users.
Right now iOS SDK doesn't provide methods for send file, live chat. This feature is under Beta testing right now. We are developing easy interface for end users, and we need more time for this. I hope, we will finish it at the end of December.
However, we allow developers develop this feature themself.
What you need for this?
- Just create simple TCP/UDP socket between 2 users and send files, audio/video stream through it
- For 1 you need to know each other ip address & port - there is STUN protocol that allow to know own address(IP & port) - here is my iOS implementation of STUN protocol https://github.com/soulfly/STUN-iOS
- If you already know your address (IP & port) - just send it to your opponent through simple Chat messages - then do 1 item.
Thats all what you need
UPD:
QuickBlox has released VideoChat and Unlimited API Calls for Developers http://quickblox.com/blog/2013/02/quickblox-updates-videochat-and-unlimited-api-calls-for-developers
So, if you want to play with the code and integrate it with your apps, check the Simple Code Sample for iOS http://quickblox.com/developers/SimpleSample-videochat-ios
You have a uploadMethod like this,
-(IBAction)uploadFile:(id)sender
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.allowsEditing = NO;
self.imagePicker.delegate = self;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
and in the QBChatDelegate, you have this method
- (void)completedWithResult:(Result*)result{
// Upload file result
if(result.success && [result isKindOfClass:[QBCFileUploadTaskResult class]])
{
QBCFileUploadTaskResult *res = (QBCFileUploadTaskResult *)result;
NSUInteger uploadedFileID = res.uploadedBlob.ID;
QBChatMessage *message = [[QBChatMessage alloc] init];
message.recipientID = self.opponent.ID;
NSMutableDictionary *msgDict = [[NSMutableDictionary alloc]init];
[msgDict setValue:[NSNumber numberWithInt:uploadedFileID] forKey:@"fileID"];
message.customParameters = msgDict;
[[QBChat instance] sendMessage:message];
}
else
{
NSLog(@"errors=%@", result.errors);
}
}
Here you are getting the uploaded file id, and you are sending this as a message..
In your chatDidReceiveNotification
- (void)chatDidReceiveMessageNotification:(NSNotification *)notification{
QBChatMessage *message = notification.userInfo[kMessage];
if(message.customParameters != nil)
{
NSUInteger fileID = [message.customParameters[@"fileID"] integerValue];
// download file by ID
[QBContent TDownloadFileWithBlobID:fileID delegate:self];
}
}
This method again calls completedWithResult
method, add this code there...
if(result.success && [result isKindOfClass:[QBCFileDownloadTaskResult class]]){
QBCFileDownloadTaskResult *res = (QBCFileDownloadTaskResult *)result;
if ([res file]) {
UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[res file]]];
[self.messages addObject:imageView];
[self.messagesTableView reloadData];
}
}else{
NSLog(@"errors=%@", result.errors);
}
If you want to display the image in your tableView, change your cellForRow like this..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[self.messages objectAtIndex:indexPath.row]isKindOfClass:[QBChatMessage class]])
{
static NSString *ChatMessageCellIdentifier = @"ChatMessageCellIdentifier";
ChatMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ChatMessageCellIdentifier];
if(cell == nil){
cell = [[ChatMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ChatMessageCellIdentifier];
}
QBChatMessage *message = (QBChatMessage *)self.messages[indexPath.row];
//
[cell configureCellWithMessage:message is1To1Chat:self.opponent != nil];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
else if ([[self.messages objectAtIndex:indexPath.row]isKindOfClass:[UIImageView class]])
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"CellIdentifier"];
}
UIImageView *receivedImage = [self.messages objectAtIndex:indexPath.row];
[cell.contentView addSubview:receivedImage];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}
I have tried this and this piece of code works.
Cheers.
If your requirement is only for 1-1 chat, then please check this link
http://quickblox.com/developers/SimpleSample-chat_users-ios#Send_files
This will work for 1-1 chat.
But, in case of room I am unable to find any solution as of now. I am trying to figure out. If anybody knows a way, please post here.