WuKongIM Docs

iOS Messages

Send, receive, retry, and read local messages while understanding message states.

A message combines WKMessageContent with a destination WKChannel. WKChatManager handles sending, receiving, local storage, and queries.

Send to a direct or group chat

WKTextContent *content = [[WKTextContent alloc] initWithContent:@"Hello"];

WKChannel *person = [WKChannel personWithChannelID:@"bob"];
WKMessage *directMessage = [[WKSDK shared].chatManager sendMessage:content
                                                           channel:person];

WKChannel *group = [WKChannel groupWithChannelID:@"team-1"];
WKMessage *groupMessage = [[WKSDK shared].chatManager sendMessage:content
                                                          channel:group];

The returned WKMessage is a local message; it does not mean the server has finished processing it. Use clientMsgNo to match it with later state changes.

Observe incoming messages and send states

[[WKSDK shared].chatManager addDelegate:self];

- (void)onRecvMessages:(WKMessage *)message left:(NSInteger)left {
    // Inspect message.content before rendering text, media, or custom content.
    [self appendMessage:message];
}

- (void)onMessageUpdate:(WKMessage *)message left:(NSInteger)left {
    [self updateMessage:message.clientMsgNo status:message.status];
}

Common states:

StateMeaningSuggested UI
WK_MESSAGE_WAITSENDStored locally and waiting to sendSending
WK_MESSAGE_UPLOADINGUploading mediaShow progress
WK_MESSAGE_SUCCESSAccepted by the serverSent
WK_MESSAGE_FAILThis send attempt failedRetry action

Retry a failed message with:

[[WKSDK shared].chatManager resendMessage:failedMessage];

Read messages for one chat

Load the latest 30 messages when opening a chat:

WKChannel *channel = [WKChannel personWithChannelID:@"bob"];
[[WKSDK shared].chatManager pullLastMessages:channel
                                       limit:30
                                    complete:^(NSArray<WKMessage *> *messages, NSError *error) {
    if (error == nil) {
        [self showMessages:messages];
    }
}];

Use pullDown:startOrderSeq:limit:complete: for older pages and pullUp:startOrderSeq:limit:complete: toward newer messages.

Remove the delegate

[[WKSDK shared].chatManager removeDelegate:self];

Do not repeatedly add the same delegate from multiple screens without removing it, or one message can produce duplicate UI updates. See Media & History for remote history and media tasks.

On this page