简体   繁体   English

发送附件到QuickBlox IOS SDK

[英]Send attachment to QuickBlox IOS sdk

I have downloaded the quickblox sample chat application and sending text messages are working fine. 我已经下载了quickblox示例聊天应用程序,并且发送短信正常。 But how to send attachment like picture, video or else? 但是如何发送图片,视频等附件?

According to Quickblox's documentation. 根据Quickblox的文档。 There is class named QBChatAttachment having properties as type , url and id but how to attach files like picture, video or else? 有一个名为QBChatAttachment的类, 具有typeurlid属性,但是如何附加图片,视频等文件呢?

Please Proper read SimpleSample-chat users-ios in this link they have mention all detail regarding how to send attachment and how to receive and download attachment etc . 请正确阅读SimpleSample-chat users-ios在此链接中,他们提到了有关如何发送附件以及如何接收和下载附件等所有详细信息。

For sending and receiving attachment in quickbox follow this link Send and Receive Attachment 要在Quickbox中发送和接收附件,请点击此链接发送和接收附件

Detail Explanation: 详细说明:

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 1)文件内容模块示例

2) A file in Custom Objects module Example 2)自定义对象模块中的文件示例

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. 您应该使用上面的示例将文件上传到“内容”模块,“自定义对象”模块或使用url到Internet中的任何文件。 Then you should incorporate an ID to file to message. 然后,您应该合并一个ID以归档到消息中。

For example, we use Content module to store attachments. 例如,我们使用Content模块存储附件。 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. 例如,我们使用Content模块存储附件。 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]]; } } 

I hope it will be helpful for you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM