首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QuickBlox :如何在点对点聊天模块中共享图像/视频?

QuickBlox :如何在点对点聊天模块中共享图像/视频?
EN

Stack Overflow用户
提问于 2012-11-28 13:01:28
回答 4查看 4.8K关注 0票数 4

我试图在聊天模块中共享图像/视频。为此,我参考了示例代码,但找不到任何帮助。

我已经提到了http://quickblox.com/modules/chat/,它说通过插入功能齐全的聊天模块,将实时聊天功能添加到应用程序中。快速,防火墙友好,健壮和安全。这是否意味着我必须购买功能齐全的聊天模块?

请建议我走正确的路。

谢谢

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-12-02 13:04:45

是的,QuickBlox聊天允许在两个用户之间共享文件、视频/音频。

现在,iOS SDK不提供发送文件、实时聊天的方法。这个特性现在正处于Beta测试之下。我们正在为最终用户开发简单的界面,我们需要更多的时间。我希望我们能在12月底完成。

但是,我们允许开发人员自己开发这个特性。你需要什么?

  1. 只需在两个用户之间创建简单的TCP/UDP套接字,并通过它发送文件、音频/视频流。
  2. 对于1,您需要了解对方的ip地址和端口--这里有允许知道自己地址(IP和端口)的STUN协议--这里是我的STUN协议https://github.com/soulfly/STUN-iOS的iOS实现。
  3. 如果您已经知道您的地址(IP &端口)--只需通过简单的聊天消息将其发送给您的对手--那么执行1项。

这就是你所需要的

票数 5
EN

Stack Overflow用户

发布于 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的简单代码示例

票数 2
EN

Stack Overflow用户

发布于 2014-02-21 12:32:14

你有一个这样的uploadMethod,

代码语言:javascript
复制
-(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中,您有这样的方法

代码语言:javascript
复制
- (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里

代码语言:javascript
复制
- (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方法,将此代码添加到.

代码语言:javascript
复制
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。

代码语言:javascript
复制
- (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;

    }
}

我已经尝试过了,这段代码也能工作。干杯。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13605664

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档