How to implement IM function in the app seven fast implementation chat list sorting module--Arrow Buckle technology Arrownock

Source: Internet
Author: User

How to implement the IM function in the app seven fast implementation chat list sorting module

A device due to the user's habit differences, may cause the device time and the actual time to send and receive messages different, here with you to share the use of Anim to send and receive messages, how to according to the data MsgId and timestamp to sort.

Implementing logic

When sending a message, we need to call Anim's SendMessage method (the same method as Sendbinary, Sendmessagetotopic, etc.), this method has a return data of MessageID, that is, the current chat message unique identity, We need to save this messageid.

Take iOS code for example:


MsgId is the unique identifier of the message nsstring *msgid = [AnIM sendmessage:message customdata:customdata Toclients:clientid needrecei Veack:yes];



After calling the SendMessage method, the SDK will unify the callback Messagesent method, the input parameters in this method is animmessagesentcallbackdata in the Android SDK, It contains two main fields, the MsgId of type string and the timestame of long, whereas in the iOS SDK are nsnumber of type MsgId and timestamp of type NSString.


(void) AnIM: (AnIM *) AnIM messagesent: (NSString *) messageId at: (NSNumber *) timestamp {//messageid calls SendMessage, etc. The message returned by the method is uniquely identified//in which the message is judged based on MessageID, and then the chat message data is saved to the local database};



When the message is received, different methods will be executed for different types of messages, regardless of which method, the input parameters of the method will have 2 and the same fields MsgId and timestamp when the message is sent.


(void) AnIM: (AnIM *) AnIM didreceivemessage: (NSString *) message customData: (Nsdictionary *) CustomData from: (NSString *) From Parties: (Nsset *) Parties MessageId: (NSString *) messageId at: (NSNumber *) Timestamp {//messageid The message when the message is sent One identity}



Timestamp is a 13-bit timestamp format that is returned from the server instead of being generated locally, thus avoiding the order in which messages are sent and received as a result of the user's own usage habits. Finally, sort according to the timestamp field, but don't forget to switch when the interface is displayed.

How to implement the IM feature series in the app article:

A common analysis of offline messages

The second fast realization of the offline message module

Three fast implementation of offline message push module

The four create a robust message sending module

The five rapid implementation of picture receiving and sending

The six fast realization of group chat advanced features

Seven fast implementation of chat list sorting module



This article from "Arrow Buckle technology Arrownock" blog, reproduced please contact the author!

How to implement IM function in the app seven fast implementation chat list sorting module--Arrow Buckle technology Arrownock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.