QuickBlox:如何在点对点聊天模块中分享图片/视频?

4
我正在尝试在聊天模块中分享图像/视频。我参考了示例代码,但没有找到任何帮助。
我还参考了http://quickblox.com/modules/chat/,它说通过插入我们的全功能聊天模块将实时聊天功能添加到您的应用程序中。快速、防火墙友好、强大且安全。这是否意味着我必须购买全功能聊天模块?
请建议我正确的方法。
谢谢
4个回答

5
是的,QuickBlox聊天允许两个用户之间共享文件、视频/音频。
目前iOS SDK没有提供发送文件、实时聊天的方法。这个功能正在Beta测试中,我们正在为最终用户开发易于使用的界面,需要更多时间。我希望我们能在12月底完成它。
但是,我们允许开发者自己开发此功能。 你需要什么?
1.只需在2个用户之间创建简单的TCP/UDP套接字,并通过它发送文件、音频/视频流。 2.对于1,您需要知道彼此的IP地址和端口 - 有STUN协议可以了解自己的地址(IP和端口) - 这是我iOS STUN协议的实现 https://github.com/soulfly/STUN-iOS 3.如果您已经知道自己的地址(IP和端口)- 只需通过简单的聊天消息将其发送给对手 - 然后执行1项。
这就是你所需要的。

嗨,我又需要使用QuickBlox SDK :) ,所以我想知道的主要事情是QuickBlox是否支持像WhatsApp一样的照片、视频分享? - Maulik
嗨,Igor,我正在当前项目中使用QuickBlox iOS SDK进行聊天。在该应用程序中,当两个用户正在聊天时,我需要向另一个用户分享(发送)图像/音频/视频。我查看了QuickBlox文档,但没有找到任何解决方案。我在我的应用程序中使用的是QuickBlox iOS SDK 2.0。那么,你能告诉我QuickBlox iOS SDK 2.0是否允许在两个用户之间共享文件、视频/音频吗? - ggg_1120

2
你有一个上传方法如下所示:

您有一个这样的上传方法,

-(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;

    }
}

我尝试过这段代码,它可以正常工作。祝好。


附加的图像只会显示给收件人,发送者不会看到。请告诉我是否有解决方案,谢谢。 - Dhekra Zaied

2

Android正在进行测试,预计将在一周内发布。 - Rubycon
@IgorKhomenko,在两个用户或群聊之间共享内容方面是否已经添加了任何示例? - Xander
@Xander,你所说的内容共享是什么意思? - Rubycon

0

聊天室内的内容共享有进展了吗?或者只是建立用户之间的群聊? - Sauron

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接