IMSDK
IM features a comprehensive suite of solutions including global access, one-to-one chat, group chat, message push, profile and relationship chain hosting, and account authentication. It also provides complete app access and backend management APIs.
V2TIMManager+Messageabstract
Swift - V2TIMManager
Swift

Extensions on V2TIMManager

Methods

add​Advanced​Msg​Listener(listener:​)

public func addAdvancedMsgListener(listener: V2TIMAdvancedMsgListener)  

1.1 Add an event listener for advanced messages

remove​Advanced​Msg​Listener(listener:​)

public func removeAdvancedMsgListener(listener: V2TIMAdvancedMsgListener)  

1.2 Remove the event listener for advanced messages

create​Text​Message(text:​)

public func createTextMessage(text: String) -> V2TIMMessage?  

2.1 Create a text message

create​Text​AtMessage(text:​at​User​List:​)

@available(*, deprecated, message: "use createAtSignedGroupMessage(message:atUserList:) instead")
    public func createTextAtMessage(text: String, atUserList: Array<String>) ->V2TIMMessage?  

2.2 Create a text message with the mentioning(@) feature

You can mention someone only in group chats. For example, if you want the current text message to @denny, @lucy, and @all, pass in ["denny", "lucy", kImSDK_MesssageAtALL] for atUserList.

  • The maximum number of @ target users is 30 by default. If this limit is exceeded, message sending will fail.

  • The total number of users specified by atUserList cannot exceed the default maximum number, including the case of @all.

  • AVChatRoom groups do not support @ messages.

Parameters

at​User​List Array<String>

List of @ target users. To @all, please pass in the kImSDK_MesssageAtALL constant string.

create​Custom​Message(data:​)

public func createCustomMessage(data: Data) -> V2TIMMessage?  

2.3 Create a custom message

create​Custom​Message(data:​desc:​ext:​)

public func createCustomMessage(data: Data, desc: String, ext: String) -> V2TIMMessage?  

2.4 Create a custom message and set offline push information

Parameters

desc String

Custom message description to be displayed for offline push

extension

Extension field for offline push

create​Image​Message(image​Path:​)

public func createImageMessage(imagePath: String) -> V2TIMMessage?  

2.5 Create an image message (image size limit: 28 MB)

create​Sound​Message(audio​File​Path:​duration:​)

public func createSoundMessage(audioFilePath: String, duration: Int) -> V2TIMMessage?  

2.6 Create a voice message (voice size limit: 28 MB)

Parameters

duration Int

Voice duration, in seconds

create​Video​Message(video​File​Path:​type:​duration:​snapshot​Path:​)

public func createVideoMessage(videoFilePath: String, type: String, duration: Int, snapshotPath: String) -> V2TIMMessage?  

2.7 Create a video message (video size limit: 100 MB)

Parameters

type String

Video type, such as mp4 and mov

duration Int

Video duration, in seconds

snapshot​Path String

Video cover image path

create​File​Message(file​Path:​file​Name:​)

public func createFileMessage(filePath: String, fileName: String) -> V2TIMMessage?  

2.8 Create a file message (file size limit: 100 MB)

create​Location​Message(desc:​longitude:​latitude:​)

public func createLocationMessage(desc: String, longitude: Double, latitude: Double) -> V2TIMMessage?  

2.9 Create a location message

create​Face​Message(index:​data:​)

public func createFaceMessage(index: Int, data: Data?) -> V2TIMMessage?  

2.10 Create an emoji message

The Chat SDK does not provide an emoji package. Developers can use index to store the indexes of the emojis they have in their emoji packages. Alternatively, they can directly use data to store emoji binary data and the string key. Either way, developers can customize emojis. The Chat SDK is only responsible for passing them through.

Parameters

index Int

Emoji index

data Data?

Custom data

create​Merger​Message(message​List:​title:​abstract​List:​compatible​Text:​)

public func createMergerMessage(messageList: Array<V2TIMMessage>, title: String?, abstractList: Array<String>, compatibleText: String) -> V2TIMMessage?  

2.11 Create a combined message (supported only in 5.2.210 and later versions)

A typical combined message looks like this on the UI:

|Chat History of Vinson and Lynx | -- title

|Vinson: When is the new version of SDK scheduled to go online? | -- abstract1

|Lynx: Next Monday. The specific time depends on the system test result in these two days. | -- abstract2

|Vinson: OK | -- abstract3

The chat UI usually displays only the title and abstract of the combined message. The complete combined message list will be displayed only when the user clicks the combined message on the UI.

You can create a combined message (V2TIMMessage) for multiple messages to be forwarded and call the sendMessage API to send the combined message. The procedure is as follows:

1. Call createMergerMessage to create a combined message V2TIMMessage.

2. Call sendMessage to send the forward V2TIMMessage.

The procedure for parsing a combined message received is as follows:

1. Obtain mergerElem via V2TIMMessage.

2. Obtain title and abstractList via mergerElem for UI display.

3. When the user clicks the combined message on the UI, call downloadMessageList to get the list of forwarded messages. for a text message, the format can be "sender:text" format. For an image message, the format can be "sender:[image]". For a file message, the format can be in the "sender:[file]". - Parameters: - messageList : Message list (Up to 300 messages are supported. The message object must be in the V2TIM_MSG_STATUS_SEND_SUCC status. The message type cannot be V2TIMGroupTipsElem.) - title : Source of the combined message, for example, "Chat History of Vinson and Lynx" and "xxx group chat history" - abstractList : Combined message abstract list (supports up to 5 abstracts, each containing a maximum of 100 characters). You can use different abstract formats for different message types. For example, - compatibleText : Text to be displayed if the SDK version does not support combined messages. This parameter cannot be null.

create​Forward​Message(message:​)

public func createForwardMessage(message: V2TIMMessage) -> V2TIMMessage?  

2.12 Create a forward message (supported only in 5.2.210 and later versions)

If you need to forward a message, you cannot directly call the sendMessage API to send the original message. Instead, you need to call createForwardMessage to create a forward message first and send it.

Parameters

message V2TIMMessage

Message object to be forwarded. The message status must be V2TIM_MSG_STATUS_SEND_SUCC. The message type cannot be V2TIMGroupTipsElem.

Returns

Forward message object. The elem content is the same as the original message.

create​Targeted​Group​Message(message:​receiver​List:​)

public func createTargetedGroupMessage(message: V2TIMMessage, receiverList: Array<String>) -> V2TIMMessage?  

2.13 Create a targeted group message(supported only in 6.0 and later versions)

If you need to send a message to a specified group member list within a group, you can create a targeted group message. Only the specified group member can receive the targeted group message.

  • The original message object does not support group @ message.

  • You can specify up to 50 message receivers.

  • Targeted group messages are not supported in community or avchatroom groups.

  • Targeted group messages will not be counted as unread messages.

Parameters

message V2TIMMessage

Original message object

receiver​List Array<String>

Message receivers

Returns

Targeted group message object

create​AtSigned​Group​Message(message:​at​User​List:​)

public func createAtSignedGroupMessage(message: V2TIMMessage, atUserList: Array<String>) -> V2TIMMessage?  

2.14 Create a group message that mentions others(supported only in 7.0 and later versions)

If you need to send a group message with the mentioning (@) feature, use this API to create a message. For example, if you want the current message to @denny, @lucy, and @all, pass in @[@"denny", @"lucy", kImSDK_MesssageAtALL] for atUserList.

  • The maximum number of @ target users is 30 by default. If this limit is exceeded, message sending will fail.

  • The total number of users specified by atUserList cannot exceed the default maximum number, including the case of @all.

  • AVChatRoom groups do not support @ messages.

Parameters

message V2TIMMessage

Original message object

at​User​List Array<String>

List of @ target users. To @all, please pass in the kImSDK_MesssageAtALL constant string.

Returns

Group @ message object

send​Message(message:​receiver:​group​ID:​priority:​online​User​Only:​offline​Push​Info:​progress:​succ:​fail:​)

public func sendMessage(message: V2TIMMessage,
                            receiver: String?,groupID: String?,
                            priority: V2TIMMessagePriority,
                            onlineUserOnly: Bool,
                            offlinePushInfo: V2TIMOfflinePushInfo?,
                            progress: V2TIMProgress?,
                            succ: V2TIMSucc?,
                            fail: V2TIMFail?) -> String?  

3.1 Send an advanced message (advanced version: provides the features of specifying message priorities and push information)

  • In v6.0 or later, you can specify both groupID and receiver, and the message will be sent to the specified user in the group. If you want to send a message to multiple users in a group, you need to call the createTargetedGroupMessage API to create a targeted group message first.

  • Before setting the offlinePushInfo field, you need to enable push via V2TIMOfflinePushManager. After push is enabled, all messages except custom messages will be pushed by default.

  • If you want to push custom messages as well, set the desc field in offlinePushInfo so that the information specified by desc will be displayed by default during push.

  • Audio-video groups (AVChatRoom) do not support the onlineUserOnly field. You need to set onlineUserOnly to false for audio-video groups (AVChatRoom).

  • If onlineUserOnly is set to true, the message is an online message and is not counted as an unread message.

Parameters

message V2TIMMessage

Message object to be sent, which needs to be created via the corresponding message creation API

receiver String?

Message recipient's userID. For a one-to-one message, you only need to specify this field.

group​ID String?

Target group ID. For a group chat message, you only need to specify this field.

priority V2TIMMessage​Priority

Message priorities. This field is valid only for group chat messages. You are advised to set higher priorities for important messages (such as red packet and gift messages) and set lower priorities for frequent but unimportant messages (such as like messages).

online​User​Only Bool

Whether the message can be received only by online users. If this field is set to true, the message will not appear in the recipient's historical message list. This field is often used to implement less important notifications such as typing indicators. This field is not supported by audio-video groups (AVChatRoom).

offline​Push​Info V2TIMOffline​Push​Info?

Title and voice carried when the message pushing offline.

Returns

msgID Unique ID of the message

set​C2CReceive​Message​Opt(user​IDList:​opt:​succ:​fail:​)

public func setC2CReceiveMessageOpt(userIDList: Array<String>, opt: V2TIMReceiveMessageOpt, succ: V2TIMSucc?, fail: V2TIMFail?)  

4.1 Set the one-to-one message receiving option for specified users (batch setting supported)

Supported only in 5.3.425 and later versions. V2TIMMessage.V2TIM_RECEIVE_MESSAGE: messages will be received when the user is online, and push notifications will be received when the user is offline. V2TIMMessage.V2TIM_NOT_RECEIVE_MESSAGE: no message will be received. V2TIMMessage.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE: messages will be received when the user is online, and no push notification will be received when the user is offline. - Parameters: - opt : There are three message receiving options: - Warning: Notes: * This API supports batch setting. You can use the userIDList field to specify up to 30 users for batch setting. * This API can be called for up to 5 times per second.

get​C2CReceive​Message​Opt(user​IDList:​succ:​fail:​)

public func getC2CReceiveMessageOpt(userIDList: Array<String>, succ: V2TIMReceiveMessageOptListSucc?, fail: V2TIMFail?)  

4.2 Query the one-to-one message receiving option for specified users

Supported only in 5.3.425 and later versions.

set​Group​Receive​Message​Opt(group​ID:​opt:​succ:​fail:​)

public func setGroupReceiveMessageOpt(groupID: String, opt: V2TIMReceiveMessageOpt, succ: V2TIMSucc?, fail: V2TIMFail?)  

4.3 Set the group message receiving option

set​All​Receive​Message​Opt(opt:​start​Hour:​start​Minute:​start​Second:​duration:​succ:​fail:​)

public func setAllReceiveMessageOpt(opt: V2TIMReceiveMessageOpt, startHour: Int, startMinute: Int, startSecond: Int, duration: Int, succ: V2TIMSucc?, fail: V2TIMFail?)  

4.4 Set message receiving option for all conversations,supported only in 7.4 and later versions.

V2TIMReceiveMessageOpt.V2TIM_RECEIVE_MESSAGE:messages will be received when the user is online, and notifications will be received when the user is offline. V2TIMReceiveMessageOpt.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE:messages will be received when the user is online, and no push notification will be received when the user is offline.(you can use this to mute group chat notifications)

  • If duration is less than 246060, group chat notifications will be muted starting from "startHour:startMinute:startSecond" every day and unmuted after the specified duration elapses.

  • If the duration is 246061 or longer, group chat notifications will be muted indefinitely starting from startHour:startMinute:startSecond of the day when the API is called.

Parameters

opt V2TIMReceive​Message​Opt

There are two message receiving options for you to choose:

start​Hour Int

(0 - 23) The starting hour of the muting duration

start​Minute Int

(0 - 59) The starting minute of the muting duration

start​Second Int

(0 - 59) The starting second of the muting duration

duration Int

(0 - 246060) The muting duration in seconds

set​All​Receive​Message​Opt(opt:​start​Time​Stamp:​duration:​succ:​fail:​)

public func setAllReceiveMessageOpt(opt: V2TIMReceiveMessageOpt, startTimeStamp: Int, duration: Int, succ: V2TIMSucc?, fail: V2TIMFail?)  

4.5 Set message receiving option for all conversations,supported only in 7.4 and later versions.

V2TIMReceiveMessageOpt.V2TIM_RECEIVE_MESSAGE:messages will be received when the user is online, and notifications will be received when the user is offline. V2TIMReceiveMessageOpt.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE:messages will be received when the user is online, and no push notification will be received when the user is offline.(you can use this to mute group chat notifications)

Parameters

opt V2TIMReceive​Message​Opt

There are two message receiving options for you to choose:

start​Time​Stamp Int

The start time of muting, UTC timestamp, unit: second

duration Int

The muting duration in seconds

get​All​Receive​Message​Opt(succ:​fail:​)

public func getAllReceiveMessageOpt(succ: V2TIMReceiveMessageOptSucc?, fail: V2TIMFail?)  

4.6 Get the all Message receiving option,supported only in 7.4 and later versions.

get​C2CHistory​Message​List(user​ID:​count:​last​Msg:​succ:​fail:​)

public func getC2CHistoryMessageList(userID: String, count: Int, lastMsg: V2TIMMessage?, succ: V2TIMMessageListSucc?, fail: V2TIMFail?)  

5.1 Get historical one-to-one messages

  • If the login API is not called,calling this API will not return any historical messages.

  • If login failed, calling this API will return local historical messages.

  • If login is successful and the network is disconnected, calling this API will return local historical messages.

  • If login is successful and the network is normal, after this API is called, cloud historical messages will be pulled first, which will be merged with local historical messages before being returned.

Parameters

count Int

Number of messages pulled at a time. The value of this field cannot be too large; otherwise, the pulling speed is affected. We recommend that you pull 20 messages at a time.

last​Msg V2TIMMessage?

Start message for message pulling. If null is passed in, the newest message of the conversation will be considered as the start message.

get​Group​History​Message​List(group​ID:​count:​last​Msg:​succ:​fail:​)

public func getGroupHistoryMessageList(groupID: String, count: Int, lastMsg: V2TIMMessage?, succ: V2TIMMessageListSucc?, fail: V2TIMFail?)  

5.2 Get historical group messages

  • If the login API is not called,calling this API will not return any historical messages.

  • If login failed, calling this API will return local historical messages.

  • If login is successful and the network is disconnected, calling this API will return local historical messages.

  • If login is successful and the network is normal, after this API is called, cloud historical messages will be pulled first, which will be merged with local historical messages before being returned.

  • Only meeting groups (Meeting) support pulling historical messages of members before they join the groups. For audio-video groups (AVChatRoom), messages are not saved to the roaming and local databases, and therefore this API does not take effect.

Parameters

count Int

Number of messages pulled at a time. The value of this field cannot be too large; otherwise, the pulling speed is affected. We recommend that you pull 20 messages at a time.

last​Msg V2TIMMessage?

Start message for message pulling. If null is passed in, the newest message of the conversation will be considered as the start message.

get​History​Message​List(option:​succ:​fail:​)

public func getHistoryMessageList(option: V2TIMMessageListGetOption, succ: V2TIMMessageListSucc?, fail: V2TIMFail?)  

5.3 Get historical messages (advanced API)

  • If the login interface is not called,calling this interface will not return any historical messages.

  • If the login is failed, calling this interface will return local historical messages.

  • If the login is successful and the network is disconnected, calling this interface will return local historical messages.

  • If the login is successful and the network is connected, when the option param is set to pull cloud historical messages, calling this interface will first request cloud historical messages, and then merge them with local historical messages before returning.

  • Only meeting groups (Meeting) support pulling historical messages of members before they join the groups. For audio-video groups (AVChatRoom), messages are not saved to the roaming and local databases, and therefore this API does not take effect.

Parameters

option V2TIMMessage​List​Get​Option

Message pulling option, which can be set to pull older or newer messages from local storage or the cloud

revoke​Message(msg:​succ:​fail:​)

public func revokeMessage(msg: V2TIMMessage, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.4 Recall messages

  • By default, you can recall only messages that are sent within 2 minutes. You can customize the time limit for message recall via the console (Feature Configuration -> Login and Message -> Message Recall Settings).

  • Only common messages sent in one-to-one chats and group chats can be recalled. You cannot recall messages that can be received only by online users (onlineUserOnly is set to true).

  • If the sender recalls a message, the recipient will receive the V2TIMAdvancedMsgListener -> onRecvMessageRevoked callback.

  • This API is available for all group types, including audio-video groups (AVChatRoom) and community groups, in 7.4 and later versions.

  • In one-to-one chats, messages can only be recalled by their senders.

  • In group chats, not only the sender can recall their own message, but administrators or group owners can also recall messages sent by other group members through this API.

modify​Message(msg:​completion:​)

public func modifyMessage(msg: V2TIMMessage, completion: V2TIMMessageModifyCompletion?)  

5.5 Modify a message

  • If the message is modified successfully, both the sender and recipients (of one-to-one or group messages) will receive the onRecvMessageModified callback.

  • While a message is being modified, if another user successfully modified it, the ERR_SDK_MSG_MODIFY_CONFLICT error will be returned upon completion.

  • The latest message object will be returned regardless of whether a message is modified successfully.

delete​Message​From​Local​Storage(msg:​succ:​fail:​)

public func deleteMessageFromLocalStorage(msg: V2TIMMessage, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.6 Delete a message from local storage

  • However, after the app is uninstalled and reinstalled, the local delete marker of the message will get lost, and the message can still be pulled via getHistoryMessage.

delete​Messages(msg​List:​succ:​fail:​)

public func deleteMessages(msgList: Array<V2TIMMessage>, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.7 Delete messages from local storage and the cloud

  • Up to 50 messages can be deleted at a time.

  • The messages to be deleted at a time must belong to the same conversation.

  • This API can be called only once per second.

  • If the account has pulled these messages from other devices, the messages will still be stored on those devices after this API is called to delete them. That is, the operation of message deletion cannot be synchronized across multiple devices.

clear​C2CHistory​Message(user​ID:​succ:​fail:​)

public func clearC2CHistoryMessage(userID: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.8 Clear chat history with a user from local storage and the cloud (without deleting the conversation)

Supported only in 5.4.666 and later versions. - Warning: Notes: * When messages in a conversation are deleted from local storage, they are deleted simultaneously from the server.

clear​Group​History​Message(group​ID:​succ:​fail:​)

public func clearGroupHistoryMessage(groupID: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.9 Clear chat history of a group from local storage and the cloud (without deleting the conversation)

Supported only in 5.4.666 and later versions. - Warning: Note that: * When messages in a conversation are deleted from local storage, they are also deleted from the server.

insert​Group​Message​ToLocal​Storage(msg:​to:​sender:​succ:​fail:​)

public func insertGroupMessageToLocalStorage(msg: V2TIMMessage, to groupID: String, sender: String, succ: V2TIMSucc?, fail: V2TIMFail?) -> String?  

5.10 Add a message to the group message list

This API is mainly used to insert informative messages in a group chat, such as "you have exited the group". Such messages are shown to the local user but not sent to others. In this sense, insertGroupMessageToLocalStorage() is sendMessage() API with the message delivery feature disabled.

Returns

msgID Unique ID of a message

insert​C2CMessage​ToLocal​Storage(msg:​to:​sender:​succ:​fail:​)

public func insertC2CMessageToLocalStorage(msg: V2TIMMessage, to userID: String, sender: String, succ: V2TIMSucc?, fail: V2TIMFail?) -> String?  

5.11 Insert a message in a one-to-one chat

This API is mainly used to insert informative messages in a one-to-one, such as "you have successfully sent the message". Such messages are shown to the local user but not sent to the remote user. In this sense, insertGroupMessageToLocalStorage() is sendMessage() API with the message delivery feature disabled.

Returns

msgID Unique ID of a message

find​Messages(message​IDList:​succ:​fail:​)

public func findMessages(messageIDList: Array<String>, succ: @escaping V2TIMMessageListSucc, fail: @escaping V2TIMFail)  

5.12 Query local messages in a specified conversation by messageID

Parameters

message​IDList Array<String>

Message ID list

search​Local​Messages(param:​succ:​fail:​)

public func searchLocalMessages(param: V2TIMMessageSearchParam, succ: @escaping V2TIMSearchMessageListSucc, fail: @escaping V2TIMFail)  

5.13 Search for local messages (supported only in Chat Premium 5.4.666 and later versions)

Parameters

search​Param

Message search parameter. For details, see the definition of V2TIMMessageSearchParam.

search​Cloud​Messages(param:​succ:​fail:​)

public func searchCloudMessages(param: V2TIMMessageSearchParam, succ: @escaping V2TIMSearchMessageListSucc, fail: @escaping V2TIMFail)  

5.14 Search for cloud messages (supported only in 7.3 and later versions)

  • This feature is a value-added service of Chat. Please refer to the pricing details for more information.

  • If you have not activated this service, calling the interface will return error code 60020.

Parameters

search​Param

Message search parameter. For details, see the definition of V2TIMMessageSearchParam.

send​Message​Read​Receipts(message​List:​succ:​fail:​)

public func sendMessageReadReceipts(messageList: Array<V2TIMMessage>, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.15 Send read receipts to the message sender (supported only in Chat Premium 6.1 and later versions)

  • To send a read receipt for a group message, you need to turn on the corresponding feature in the Chat console.

  • The messages in messageList must be in the same conversation.

  • After the API is called successfully, the sender's message unread count will not change. Instead, the sender will receive the onRecvMessageReadReceipts callback, which indicates whether the message has been read.

get​Message​Read​Receipts(message​List:​succ:​fail:​)

public func getMessageReadReceipts(messageList: Array<V2TIMMessage>, succ: @escaping V2TIMMessageReadReceiptsSucc, fail: @escaping V2TIMFail)  

5.16 Get read receipts for messages sent (Supported only in Chat Premium 6.1 and later versions)

  • To obtain the read receipt of group message, you need to go to the console and turn on the corresponding switch.

  • The messages in messageList must be in the same conversation.

get​Group​Message​Read​Member​List(message:​filter:​next​Seq:​count:​succ:​fail:​)

public func getGroupMessageReadMemberList(message: V2TIMMessage, filter: V2TIMGroupMessageReadMembersFilter, nextSeq: UInt, count: UInt, succ: @escaping V2TIMGroupMessageReadMemberListSucc, fail: @escaping V2TIMFail)  

5.17 Get group members who have read a group message (Supported only in Chat Premium 6.1 and later)

Parameters

message V2TIMMessage

group message

filter V2TIMGroup​Message​Read​Members​Filter

Whether to get members who have or who have not read the message.

next​Seq UInt

Pulling-by-page cursor. It is set to 0 when the information is pulled for the first time. The value of this field in the callback for the current paginated pulling is passed in for the next pull.

count UInt

Number of read members pulled per page. maximum support 100.

set​Message​Extensions(message:​extensions:​succ:​fail:​)

public func setMessageExtensions(message: V2TIMMessage, extensions: Array<V2TIMMessageExtension>, succ: V2TIMMessageExtensionsSetSucc?, fail: V2TIMFail?)  

5.18 Set message extensions (supported only in 6.7 and later versions)

  • You need to buy Premium Edition to use this feature. And you need to go to the IM console to enable this feature.

  • The extension key supports a maximum of 100 bytes, the extension value supports a maximum of 1KB, a maximum of 20 extensions can be set at a time, and a maximum of 300 extensions can be set for a single message.

  • If multiple users set the same extension key at the same time, only the first user can execute it successfully. The other users will receive the 23001 error code and the newest extension information, and can try again afterward.

  • We strongly recommend that different users set different extension keys, so that conflict will not appear in most scenarios. For example, you can use your userID as an extension key for voting, solitaire, and questionnaires.

Parameters

message V2TIMMessage

The target message must be sent successfully and its supportMessageExtension field must be set to true before sending. In addition, AVChatRoom message do not support this feature.

extensions Array<V2TIMMessage​Extension>

The existing message extensions will be updated, and non-existing message extensions will be added directly.

get​Message​Extensions(message:​succ:​fail:​)

public func getMessageExtensions(message: V2TIMMessage, succ: @escaping V2TIMMessageExtensionsGetSucc, fail: @escaping V2TIMFail)  

5.19 Get message extensions (supported only in 6.7 and later versions)

delete​Message​Extensions(message:​keys:​succ:​fail:​)

public func deleteMessageExtensions(message: V2TIMMessage, keys: Array<String>?, succ: V2TIMMessageExtensionsDeleteSucc?, fail: V2TIMFail?)  

5.20 Delete message extensions (supported only in 6.7 and later versions)

  • If multiple users delete the same extension key at the same time, only the first user can execute it successfully. The other users will receive the 23001 error code and the newest extension information, and can try again afterward.

Parameters

keys Array<String>?

Message extension key list. If this is null, it means to delete all extensions of the message.

add​Message​Reaction(message:​reaction​ID:​succ:​fail:​)

public func addMessageReaction(message: V2TIMMessage, reactionID: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.21 Add a message reaction (can be used for emoji response) (supported only in 7.4 and later versions)

Emoji response function refers to the interaction response to a message through emoji symbols. We can see the number of responses and the list of responders for each emoji.

Currently, there are two common styles of message response display:

Style one:

----------------------------

| lucy, happy birthday! |

----------------------------

| 😄 1 💐 2 👍🏻 10 |

----------------------------

Style two:

---------------------------------------------------------

| lucy, happy birthday! |

---------------------------------------------------------

| 😁 bob 💐olivia 🎂david |

| 👍🏻 denny、james、lucy、linda、thomas and other 10 people |

----------------------------------------------------------

When the user clicks on an emoji, it will jump to the emoji response detail interface:

| 😄 | 💐 | 👍🏻 |

| bob | olivia | lucy |

| ... | ... | denny |

| ... | ... | ... |

You can pull a list of users who responded with an emoji by page.

You can implement emoji response capabilities using the following SDK APIs:

1、Call addMessageReaction to add an emoji reaction to a message. If it succeeds, the current user will be added to the response list for that emoji.

2、Call removeMessageReaction to delete an added emoji reaction. If it succeeds, the current user will be removed from the response list for that emoji.

3、Call getMessageReactions to get the emoji reactions of multiple messages. The number of users who responded with each emoji and the information of the first N users (10 by default) will be returned.

4、Call getAllUserListOfMessageReaction to get the information of all users who responded with the emojis by page.

5、Listen to the onRecvMessageReactionsChanged callback to receive notifications about the change of emoji response. The callback will return the latest response information, including the total number of users who responded with each emoji and the information of the first N users.

- Parameters: - reactionID : Message reaction ID. In the emoji response scenario, reactionID is the emojiID. A single message supports up to 10 reactions, and a single reaction supports up to 100 users. - Warning: Note that: * You need to buy the Premium edition to use this feature. * If the total count of reactions in a single message exceeds the maximum limit, the interface will report ERR_SVR_MSG_REACTION_COUNT_LIMIT error. * If the total count of users in a single reaction exceeds the maximum limit, the interface will report ERR_SVR_MSG_REACTION_USER_COUNT_LIMIT error. * If the current user is already in the specified emoji's response list, the interface will report the ERR_SVR_MSG_REACTION_ALREADY_CONTAIN_USER error.

remove​Message​Reaction(message:​reaction​ID:​succ:​fail:​)

public func removeMessageReaction(message: V2TIMMessage, reactionID: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.22 Remove a message reaction (supported only in 7.4 and later versions)

  • You need to buy Premium Edition to use this feature.

  • If the reaction does not exist, the interface will report ERR_SVR_MSG_REACTION_NOT_EXISTS error.

  • If the current user is not in the specified emoji's response list, the interface will report the ERR_SVR_MSG_REACTION_NOT_CONTAIN_USER error.

get​Message​Reactions(message​List:​max​User​Count​Per​Reaction:​succ:​fail:​)

public func getMessageReactions(messageList: Array<V2TIMMessage>, maxUserCountPerReaction: UInt32, succ: V2TIMGetMessageReactionsSucc?, fail: V2TIMFail?)  

5.23 Get message reactions (supported only in 7.4 and later versions)

  • You need to buy Premium Edition to use this feature.

Parameters

message​List Array<V2TIMMessage>

Message list, supports up to 20 messages at a time, which must belong to the same conversation.

max​User​Count​Per​Reaction UInt32

The value range is 【0,10】. Every reaction only supports returning the first 10 user profile at most. If you need more user profile, you can call the getAllUserListOfMessageReaction interface to pull in pages.

get​All​User​List​OfMessage​Reaction(message:​reaction​ID:​next​Seq:​count:​succ:​fail:​)

public func getAllUserListOfMessageReaction(message: V2TIMMessage, reactionID: String, nextSeq: UInt32, count: UInt32, succ: V2TIMGetMessageReactionUserListSucc?, fail: V2TIMFail?)  

5.24 Get a list of users who responded with an emoji (supported only in 7.4 and later versions)

  • You need to buy Premium Edition to use this feature.

Parameters

message V2TIMMessage

Message object

reaction​ID String

Message reaction ID

next​Seq UInt32

The pulling-by-page cursor. Pass 0 for the first time, and pass the nextSeq returned by succ for subsequent pagination.

count UInt32

The maximum count of users fetched per page, up to 100.

translate​Text(source​Text​List:​source​Language:​target​Language:​completion:​)

public func translateText(sourceTextList: Array<String>, sourceLanguage: String, targetLanguage:String, completion:V2TIMTranslateTextCompletion?)  

5.25 Translate text message.

Parameters

source​Text​List Array<String>

Texts to be translated.

source

Source language. You can pass the specific language or "auto". "auto" means identifying the source language automatically. If you set it to nil, "auto" will be filled as default.

target

Target language. Multi languages are supported, like: English-"en", Simplified Chinese-"zh", French-"fr", German-"ge" and so on. For more languages, please refer to this documentation: Language support.

callback

Translated result callback. The key represents the source text and value represents target text.

mark​C2CMessage​AsRead(user​ID:​succ:​fail:​)

@available(*, deprecated, message: "Please call API cleanConversationUnreadMessageCount instead")
    public func markC2CMessageAsRead(userID: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.26 Mark all messages of a one-to-one conversation as read (This is to be deprecated. Please call cleanConversationUnreadMessageCount instead.)

  • After the API is successfully called, your unread count will be cleared to 0, and the remote user will receive the onRecvC2CReadReceipt callback, which will contain the time when the messages were marked as read.

  • If userID is null, all one-to-one messages will be marked as read. This is only supported in 5.8 and later versions.

mark​Group​Message​AsRead(group​ID:​succ:​fail:​)

@available(*, deprecated, message: "Please call API cleanConversationUnreadMessageCount instead")
    public func markGroupMessageAsRead(groupID: String, succ: V2TIMSucc?, fail: V2TIMFail?)  

5.27 Mark all messages of a group chat as read (This is to be deprecated. Please call cleanConversationUnreadMessageCount instead.)

  • After the API is successfully called, your unread count will be cleared to 0.

  • If the groupID is nil, all group messages wil be marked as read. More importantly, it only supported in 5.8 and later versions.

mark​All​Message​AsRead(succ:​fail:​)

@available(*, deprecated, message: "Please call API cleanConversationUnreadMessageCount instead")
    public func markAllMessageAsRead(succ: V2TIMSucc?, fail: V2TIMFail?)  

5.28 Mark all messages as read (This is to be deprecated. Please call cleanConversationUnreadMessageCount instead.)

pin​Group​Message(group​ID:​message:​is​Pinned:​succ:​fail:​)

public func pinGroupMessage(groupID: String, message: V2TIMMessage, isPinned: Bool, succ: @escaping V2TIMSucc, fail: @escaping V2TIMFail)  

5.29 Set the group message to the top(supported only in Chat Premium 7.9 and later versions)

  • The maximum number of messages that can be pinned is 10.

  • This interface is used to pin and cancel pinned group messages. If the number of pinned messages exceeds the limit, the SDK will return error code 10070.

Parameters

group​ID String

Group ID

is​Pinned Bool

Whether to pin it to the top

get​Pinned​Group​Message​List(group​ID:​succ:​fail:​)

public func getPinnedGroupMessageList(groupID: String, succ: @escaping V2TIMPinnedMessageListSucc, fail: @escaping V2TIMFail)  

5.30 Get the list of pinned group messages(supported only in Chat Premium 7.9 and later versions)

  • This interface is used to obtain the pinned message list. If the pinned message has expired, it will not be returned.

Parameters

group​ID String

Group ID