【问题标题】:Send attachment to QuickBlox IOS sdk将附件发送到 QuickBlox IOS sdk
【发布时间】:2015-10-29 03:14:44
【问题描述】:

我已经下载了 quickblox 示例聊天应用程序,并且发送短信工作正常。但是如何发送图片、视频等附件?

根据 Quickblox 的文档。 有一个名为 QBChatAttachment 的类具有 typeurlid 属性,但是如何附加图片、视频等文件不然呢?

【问题讨论】:

    标签: ios chat attachment quickblox


    【解决方案1】:

    请正确阅读此链接中的SimpleSample-chat users-ios,他们提到了有关如何发送附件以及如何接收和下载附件等的所有详细信息。

    要在 quickbox 中发送和接收附件,请点击此链接 Send and Receive Attachment

    详细说明:

    发送和接收带有附件的消息 发送附件

    可以在消息中添加附件:例如,图像、音频 文件或视频文件。我们在这里没有任何限制 - 你可以 附加任何类型的文件。

    要发送带有附件的消息,您应该使用与您相同的方式 发送带有文本的常规消息,但添加一个附件对象。 附件可以是:

    1) 一个文件内容模块Example

    2) 自定义对象模块Example中的一个文件

    发送带有附件的消息

    你应该上传一个文件到内容模块,自定义对象模块 使用上面的示例或使用 Internet 中任何文件的 url。然后你 应该包含一个 ID 来归档到消息。

    例如,我们使用 Content 模块来存储附件。下一个 sn-ps 显示

    如何将文件上传到内容模块并作为附件发送:

    // Upload a file to the Content module
       NSData *imageData = UIImagePNGRepresentation([UIImage  imageNamed:@"arrow.png"]);
    
        [QBRequest TUploadFile:imageData fileName:@"arrow.png" contentType:@"image/png" isPublic:NO successBlock:^(QBResponse
    *response, QBCBlob *uploadedBlob) {
    NSUInteger uploadedFileID = uploadedBlob.ID;
    
     // Create chat message with attach
     //
     QBChatMessage *message = [QBChatMessage message];
    
    ...
    
    QBChatAttachment *attachment = QBChatAttachment.new;
    attachment.type = @"image";
    attachment.ID = [NSString stringWithFormat:@"%d", uploadedFileID]; //use 'ID' property to store an ID of a file in Content or CustomObjects modules
    
       [message setAttachments:@[attachment]];
      } statusBlock:^(QBRequest *request, QBRequestStatus *status) {
    // handle progress            
     } errorBlock:^(QBResponse *response) {
    NSLog(@"error: %@", response.error);
     }];
    

    接收附件

    例如我们使用 Content 模块来存储附件。下一个 sn-ps 允许接收带有附件的消息并下载:

    #pragma mark QBChatDelegate
    
      - (void)chatDidReceiveMessage:(QBChatMessage *)message{
    for(QBChatAttachment *attachment in message.attachments){
        // download file by ID
        [QBRequest TDownloadFileWithBlobID:[attachment.ID integerValue] successBlock:^(QBResponse *response, NSData *fileData) {
            UIImage *image = [UIImage imageWithData:fileData];
    
        } statusBlock:^(QBRequest *request, QBRequestStatus *status) {
            // handle progress            
        } errorBlock:^(QBResponse *response) {
            NSLog(@"error: %@", response.error);
        }];
    }
    }
    

    获取附件链接并用于显示图像:

            - (void)chatDidReceiveMessage:(QBChatMessage *)message{
    for(QBChatAttachment *attachment in message.attachments){
        // or if you have only file ID
        NSString *privateUrl = [QBCBlob privateUrlForID:[attachment.ID integerValue]];
    }
    }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      相关资源
      最近更新 更多