我试图在聊天模块中共享图像/视频。为此,我参考了示例代码,但找不到任何帮助。
我已经提到了http://quickblox.com/modules/chat/,它说通过插入功能齐全的聊天模块,将实时聊天功能添加到应用程序中。快速,防火墙友好,健壮和安全。这是否意味着我必须购买功能齐全的聊天模块?
请建议我走正确的路。
谢谢
发布于 2012-12-02 13:04:45
是的,QuickBlox聊天允许在两个用户之间共享文件、视频/音频。
现在,iOS SDK不提供发送文件、实时聊天的方法。这个特性现在正处于Beta测试之下。我们正在为最终用户开发简单的界面,我们需要更多的时间。我希望我们能在12月底完成。
但是,我们允许开发人员自己开发这个特性。你需要什么?
这就是你所需要的
发布于 2013-02-21 14:11:09
UPD:
QuickBlox发布了面向开发人员http://quickblox.com/blog/2013/02/quickblox-updates-videochat-and-unlimited-api-calls-for-developers的VideoChat和无限API调用。
因此,如果您想使用代码并将其与应用程序集成,请检查iOS http://quickblox.com/developers/SimpleSample-videochat-ios的简单代码示例
发布于 2014-02-21 12:32:14
你有一个这样的uploadMethod,
-(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];
}在QBChatDelegate中,您有这样的方法
- (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);
}
}这里您正在获取上传的文件id,并将此作为一条消息发送。
在你的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];
}
}此方法再次调用completedWithResult方法,将此代码添加到.
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);
}如果您想在tableView中显示图像,请按以下方式更改您的cellForRow。
- (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;
}
}我已经尝试过了,这段代码也能工作。干杯。
https://stackoverflow.com/questions/13605664
复制相似问题