// Send message "hello" to user AWKChannel *channel = [[WKChannel alloc] initWith:@"A" channelType:WK_PERSON];// Send to group g1// WKChannel *channel = [[WKChannel alloc] initWith:@"g1" channelType:WK_GROUP];// Build a text message objectWKTextContent *content = [[WKTextContent alloc] initWithContent:@"hello"];// Send this text message to the specified channel[[WKSDK shared].chatManager sendMessage:content channel:channel];
When a message is sent, the reasonCode in the WKMessage object returned by the onMessageUpdate: or onMessageStatusUpdate: delegate methods indicates the result of the message delivery. Below are the descriptions for each status code:
Some messages may need to carry additional information, such as message read status, whether the message has been edited, etc. This information can be implemented through message extension properties.
Trigger timing: Triggered when calling [[WKSDK shared].chatManager updateMessageRemoteExtra]
Copy
// newExtra New extension data// oldExtra Old extension data[[[WKSDK shared] chatManager] setUpdateMessageExtraProvider:^(WKMessageExtra *newExtra,WKMessageExtra *oldExtra,WKUpdateMessageExtraCallback callback) { // Implement your server API call here // Call callback with result}];
Trigger timing: Triggered when calling [[WKSDK shared].chatManager syncMessageExtra]
Copy
// channel Channel to sync extension messages// extraVersion Current client data version// limit Data amount per sync// callback Should call this callback when getting messages from server (Note: callback must be called regardless of success or failure)[[[WKSDK shared] chatManager] setSyncMessageExtraProvider:^(WKChannel * _Nonnull channel, long long extraVersion,NSInteger limit, WKSyncMessageExtraCallback _Nonnull callback) { // Implement your server API call here // Call callback with result}];
Trigger timing: When getting message history and the message doesn't exist locally, SDK will call this method to complete local messagesSync channel messages. When requesting message history, SDK will check if messages exist locally. If not or missing, SDK will call this method to request messages from server.
Copy
// channel Channel to sync messages// startMessageSeq Start message sequence number// endMessageSeq End message sequence number// limit Message sync count per request// pullMode Pull message mode 0: pull down 1: pull up// callback Should call this callback when getting messages from server (Note: callback must be called regardless of success or failure)[WKSDK.shared.chatManager setSyncChannelMessageProvider:^(WKChannel * _Nonnull channel, uint32_t startMessageSeq, uint32_t endMessageSeq, NSInteger limit, WKPullMode pullMode, WKSyncChannelMessageCallback _Nonnull callback) { // Implement your server API call here // Call callback with result}];
@interface WKMessageContent : NSObject<NSCopying>/** Your custom message type, should be consistent across platforms @return Content type */- (NSNumber*) contentType;// Upper layer doesn't need to implement encode, implement this method instead- (NSDictionary*) encodeWithJSON;// Upper layer doesn't need to implement decode, implement this method instead- (void) decodeWithJSON:(NSDictionary*)contentDic;// @mention information in message@property (nonatomic, strong) WKMentionedInfo *mentionedInfo;/// Reply content@property(nonatomic,strong) WKReply *reply;@end