[IOS development] How to use Rongyun's message extension

[IOS development] How to use Rongyun's message extension

Starting from the [4.0.3] version, Rongyun has added a message extension function. The document is as follows:
https://docs.rongcloud.cn/v4/views/im/noui/guide/private/msgmanage/expansion/ios.html

Summarize several key points in the document:

  • Versions before 4.0.3 cannot be used.
  • The message extension is an attribute of the RCMessage class, which means that custom messages can also be used.
  • Only 300 kv can be set for a single message (unavailable in some scenarios, such as sending red envelopes that can be received by 400 people in a group).
  • Only single chat and group chat are supported.
  • The key and value are both string types, and the key cannot be Chinese, otherwise an INVALID_PARAMETER error will be reported.
  • When using IMKit UI to send a message, you need to intercept it and set the message extension switch.

Steps for usage:

  1. The sender of the message must turn on the switch for the message that needs message expansion. There is no global setting, only a single message setting. There are two situations:
  • If you use the UI provided by IMKit to send messages, or use the sendMessage and sendMediaMessage methods in RCConversationViewController to send messages, the following callbacks will be triggered:
/*!
 准备发送消息的回调

 @param messageContent 消息内容

 @return 修改后的消息内容

 @discussion 此回调在消息准备向外发送时会回调,您可以在此回调中对消息内容进行过滤和修改等操作。
 如果此回调的返回值不为nil,SDK会对外发送返回的消息内容。
 */
- (RCMessageContent *)willSendMessage:(RCMessageContent *)messageContent;

In the callback to determine if it is a message that needs to be expanded, construct an RCMessage object by yourself according to the messageContent, and set the canIncludeExpansion and expansionDic.

RCMessage *message = [[RCMessage alloc] initWithType:self.conversationType targetId:self.targetId direction:MessageDirection_SEND messageId:0 content:messageContent];
message.canIncludeExpansion = YES;
message.expansionDic = dict;

Then call the corresponding send method in RCIM to send the message, and return nil in the callback to send the message.

  • If you call the RCIM and RCIMClient interface to send a message, construct an RCMessage object with an object of the RCMessageContent class, then set canIncludeExpansion and expansionDic and then call the corresponding send method in RCIM to send the message.
  1. For operations to update and delete extensions, please refer to the official documentation.
  2. To capture the changes and deletions of the message extension in real time, you need to set a callback and update the UI in the callback. For setting callback, please refer to the official document.

Guess you like

Origin blog.51cto.com/15056506/2678330