logo
当前页

取消媒体消息发送


功能简介

ZIM SDK 支持取消用户正在发送包含本地媒体文件的消息,取消成功后消息状态变更为“发送失败”。

注意
  • 2.22.0 版本开始支持。
  • 仅支持取消发送的消息类型为包含本地媒体文件的 Multiple(10)、Image(11)、File(12)、Audio(13)、Video(14) 类型。

取消正在发送的媒体消息

当用户发送包含本地媒体文件的消息时,由于文件上传需要一定的耗时,在这段时间内调用 cancelSendingMessage 取消发送此条消息终止文件上传。

注意

当包含普通文本和媒体文件的组合消息被取消时,整个消息(包含普通文本)都会被取消发送。

- (void)zim:(ZIM *)zim messageSentStatusChanged:(NSArray<ZIMMessageSentStatusChangeInfo *> *)infos{
  // 消息发送状态变更
}
NSString *conversationID = @"xxx" ; // 会话 ID

// 用户 A 发送一条消息,以单聊文件消息为例

ZIMFileMessage *message = [[ZIMFileMessage alloc] init];
//需填入 UTF-8 格式的本地路径
//此处以文件选择器选中的某个文件地址为例
message.fileLocalPath = @"/private/var/mobile/Containers/Shared/AppGroup/D5144D14-3FE8-4C6C-8527-01F368B8E49E/File Provider Storage/xxx.zip";

ZIMMessageSendConfig *sendConfig = [[ZIMMessageSendConfig alloc]init];

ZIMMessageSendNotification *notification = [[ZIMMessageSendNotification alloc] init];
notification.onMessageAttached = ^(ZIMMessage * _Nonnull message) {
    // 开发者可以监听这个回调执行消息发送前的业务逻辑
};
        
notification.onMediaUploadingProgress = ^(ZIMMediaMessage * _Nonnull message, unsigned long long currentFileSize, unsigned long long totalFileSize) {
    // 处于文件上传中时,取消发送
    ZIMSendingMessageCancelConfig *cancelConfig = [[ZIMSendingMessageCancelConfig alloc]init];
    [[ZIM getInstance] cancelSendingMessage:message config:cancelConfig callback:^(ZIMError * _Nonnull errorInfo) {
        
    }];
};

[[ZIM getInstance] sendMessage:message toConversationID:conversationID conversationType:ZIMConversationTypePeer config:sendConfig notification:notification callback:^(ZIMMessage * _Nonnull message, ZIMError * _Nonnull errorInfo) {
        
}];

Previous

群定向消息

Next

获取会话列表

当前页

返回到顶部