Cancel Media Message Sending
Feature Overview
The ZIM SDK supports canceling messages containing local media files that are currently being sent. After a successful cancellation, the message status will change to "Failed to Send".
Note
- Supported from version 2.22.0.
- Only messages containing local media files of the following message types can be canceled:
Multiple(10)
,Image(11)
,File(12)
,Audio(13)
,Video(14)
.
Cancel the Media Message Being Sent
When a user sends a message containing a local media file, due to the time required for file upload, the file upload can be terminated by calling cancelSendingMessage during this period.
Note
When a multi item messages containing both ordinary text and media files is canceled, the entire message (including ordinary text) will be canceled.
- (void)zim:(ZIM *)zim messageSentStatusChanged:(NSArray<ZIMMessageSentStatusChangeInfo *> *)infos{
// Message sent status changed
}
NSString *conversationID = @"xxx" ; // Conversation ID
// User A sends a message, taking a single-chat file message as an example
ZIMFileMessage *message = [[ZIMFileMessage alloc] init];
//Enter the local path in UTF-8 format
//Here, the address of a file selected by the file selector is used as an example
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) {
// Developers can listen to this callback to execute the business logic before message sending
};
notification.onMediaUploadingProgress = ^(ZIMMediaMessage * _Nonnull message, unsigned long long currentFileSize, unsigned long long totalFileSize) {
// Cancel sending when the file is being uploaded
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) {
}];