ios - 将附件发送到 QuickBlox IOS sdk

标签 ios chat attachment quickblox

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

根据 Quickblox 的文档。
有一个类名为 QBChat附件具有 的属性类型 , 网址 编号 但是如何附加图片,视频或其他文件?

最佳答案

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

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

详细说明:

Send and receive a message with attachment Send attachment

It's possible to add attachments to message: for example, image, audio file or video file. We don't have any restrictions here - you can attach any type of file.

To send a message with attachments you should use the same way as you send regular message with text, but add to it an attachment object. Attachment can be:

1) A file content Module Example

2) A file in Custom Objects module Example

To send a message with attachment

you should upload a file to Content module, Custom Objects module using sample above or use an url to any file in Internet. Then you should incorporate an ID to file to message.

For example, we use Content module to store attachments. Next snippets show

how to upload a file to Content module and send it as an attach:

// 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);
 }];

Receive attachment

For example we use Content module to store attachments. Next snippets allow to receive a message with an attachment and download it:

#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);
    }];
}
}

to obtain a link to attachment and use to show an image:

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


我希望它对你有帮助。

关于ios - 将附件发送到 QuickBlox IOS sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31847858/

相关文章:

ios - 如何在不更改xcode中的字体系列的情况下更改标签的字体大小

用于聊天应用程序的 Java nat 遍历

php - 与 Jabber/Aim 集成的简单 web "live chat"软件(LAMP 堆栈)

安卓 Intent : Send an email with attachment

elasticsearch - ElasticSearch.net附件搜索数组正在返回带有搜索结果的所有附件,如何仅检索匹配

iOS完成 block 不返回控制

iphone - 使用编码 windows-1255 将 NSData 转换为 NSString

ios - 无法强制将类型 'GraphRequestResult<GraphRequest>' 的值转换为类型 '[Any]'

java - 无线网络聊天程序需要java代码

email - phpmailer 无名附件