4

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

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

请建议我正确的方法。

谢谢

4

4 回答 4

5

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

目前 iOS SDK 不提供发送文件、实时聊天的方法。此功能目前处于 Beta 测试阶段。我们正在为最终用户开发简单的界面,为此我们需要更多时间。我希望,我们将在 12 月底完成它。

但是,我们允许开发人员自己开发此功能。你需要什么?

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

这就是你所需要的

于 2012-12-02T13:04:45.237 回答
2

你有一个像这样的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;

    }
}

我已经尝试过了,这段代码有效。干杯。

于 2014-02-21T12:32:14.157 回答
2

更新

QuickBlox 为开发人员发布了 VideoChat 和无限 API 调用http://quickblox.com/blog/2013/02/quickblox-updates-videochat-and-unlimited-api-calls-for-developers

因此,如果您想使用代码并将其与您的应用程序集成,请查看适用于 iOS 的简单代码示例http://quickblox.com/developers/SimpleSample-videochat-ios

于 2013-02-21T14:11:09.953 回答
0

如果您的要求只是 1-1 聊天,请查看此链接 http://quickblox.com/developers/SimpleSample-chat_users-ios#Send_files 这适用于 1-1 聊天。

但是,如果有房间,我现在无法找到任何解决方案。我想弄清楚。如果有人知道方法,请在此处发布。

于 2013-11-30T08:46:27.720 回答