将附件发送到QuickBlox IOS sdk
我已经下载了quickblox示例聊天应用程序,发送文本消息工作正常。但如何发送图片、视频或其他附件 根据Quickblox的文档。 有一个名为QBChatAttachment的类,其属性为type、url和id,但如何附加像picture这样的文件,视频还是其他?请正确阅读此链接,他们提到了有关如何发送附件以及如何接收和下载附件等的所有详细信息 要在quickbox中发送和接收附件,请点击此链接 详细说明: 发送和接收带有附件的邮件发送附件 可以向邮件添加附件:例如,图像、音频 文件或视频文件。我们这里没有任何限制-你可以 附加任何类型的文件 要发送带有附件的邮件,您应使用与您相同的方式 发送带有文本的常规邮件,但向其中添加附件对象。 附件可以是: 1) 文件内容模块 2) 自定义对象模块中的文件 发送带有附件的邮件 您应该将文件上载到内容模块、自定义对象模块 使用上面的示例或使用指向Internet中任何文件的url。那你呢 应将文件ID合并到消息中 例如,我们使用内容模块来存储附件。下一个片段 展示 如何将文件上载到内容模块并作为附件发送:将附件发送到QuickBlox IOS sdk,ios,chat,attachment,quickblox,Ios,Chat,Attachment,Quickblox,我已经下载了quickblox示例聊天应用程序,发送文本消息工作正常。但如何发送图片、视频或其他附件 根据Quickblox的文档。 有一个名为QBChatAttachment的类,其属性为type、url和id,但如何附加像picture这样的文件,视频还是其他?请正确阅读此链接,他们提到了有关如何发送附件以及如何接收和下载附件等的所有详细信息 要在quickbox中发送和接收附件,请点击此链接 详细说明: 发送和接收带有附件的邮件发送附件 可以向邮件添加附件:例如,图像、音频 文件或视频文
// 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);
}];
接收附件
例如,我们使用内容模块来存储附件。下一个片段
允许接收带有附件的邮件并下载:
#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]];
}
}
我希望它能对您有所帮助。请正确阅读此链接,他们已经提到了有关如何发送附件以及如何接收和下载附件等的所有详细信息
要在quickbox中发送和接收附件,请点击此链接
详细说明:
发送和接收带有附件的邮件发送附件
可以向邮件添加附件:例如,图像、音频
文件或视频文件。我们这里没有任何限制-你可以
附加任何类型的文件
要发送带有附件的邮件,您应使用与您相同的方式
发送带有文本的常规邮件,但向其中添加附件对象。
附件可以是:
1) 文件内容模块
2) 自定义对象模块中的文件
发送带有附件的邮件
您应该将文件上载到内容模块、自定义对象模块
使用上面的示例或使用指向Internet中任何文件的url。那你呢
应将文件ID合并到消息中
例如,我们使用内容模块来存储附件。下一个片段
展示
如何将文件上载到内容模块并作为附件发送:
// 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);
}];
接收附件
例如,我们使用内容模块来存储附件。下一个片段
允许接收带有附件的邮件并下载:
#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]];
}
}
我希望这对你有帮助