One-to-one message
It takes ordinary text messages as an example in the document. If there are other data format requirements, the text can be replaced with the JSON data defined by yourself
For example, if you want to send a picture, you can upload it to your own server or use a 3rd party image storage (such as Qi Niuyun, Alibaba Cloud OSS, etc.) to upload the image and send the URL.
4.1 Receiving one-to-one messages
Get the XHChatManager class instance and set the XHChatManagerDelegate delegate
示例:[[XHClient sharedClient].chatManager addDelegate:self];
//Receiving one-to-one messages
- (void)chatMessageDidReceived:(NSString *)message fromID:(NSString *)uid {
dispatch_async(dispatch_get_main_queue(), ^{
[self showTrace:message userID:uid isMySelf:NO];
});
}
4.2 Sending one-to-one messages
The messages are divided into ordinary message(sendMessage) and online message(sendOnLineMessage).
“Normal message” refers to a normal chat message, which is cached when the user is offline, and it will be took all offline messages when they go online again.
“Online messages” are only received when the receiver is online, which are not cached.
Example:[[XHClient sharedClient].chatManager sendMessage:text toID:self.targetID completion:^(NSError *error) {
if (error) {
[UIView ilg_makeToast:@"C2c message has failed to be sent"];
} else {
}
}];
[[XHClient sharedClient].chatManager sendOnLineMessage:text toID:self.targetID completion:^(NSError *error) {
if (error) {
[UIView ilg_makeToast:@"C2c online message has failed to be sent"];
} else {
}
}];