Tencent im access process

 

1 sdk access:

  Download the sdk   from https://www.qcloud.com/product/im ,

https://www.qcloud.com/document/product/269/1565   sdk integration process.

 

2 Combined project:

  1. In the header file of the third-party initialization appkey, globalize the relevant application configuration (define macro)
  2. Application configuration address: https://console.qcloud.com/avc
  3. Fields that need to be globalized: SdkAppId accountType (If you need to push offline, you need to add a BusiId)
  4.  Initialize in the appdelegate   willFinishLauchingWithOptions method, [ timmanager sharedManager ] calls the initSdk  method, appkey and accountType  are obtained in the third part
  5. After the initialization is complete, you can monitor the message through the registered agent.
  6. Generally speaking, a messageManager class is used to handle callbacks in the project . Similarly, in the appdelegate, the Manager class (singleton) is initialized.
  7. The TIMMessageListener, TIMRefreshListener, TIMUserStatusListener, and TIMConnListener  manager classes comply with these agents to receive callbacks to handle receiving information, message refresh, user status changes, and connection status changes.
  8. New message callback: In Tencent im message processing, the following categories are mainly paid attention to:

The timConversation  session class can be understood as a conversation

The timMessage  message class can be understood as a sentence in the conversation

The timElem  message base class can be understood as, timMessage is composed of some timElem, which constitutes a sentence

timElem has many subcategories. Text, pictures, voice, etc.

(9) In the custom manager class, we monitor the callback of the received message. -(void)onNewMessage(NSArray *)msgs , returns an array, which is an array of timMessage class, we get the first element of the array msg.firstObject;

Obtain the elem message base class through the [ timMessage getElem:0 ] method.

(10) Potholes: elem may be of many types: text, picture, and custom. In my pocket, there are only messages from the system. To process a custom class, first determine whether elem is a TIMCustomElem class, and then call the data method of customElem (you must judge, otherwise it will crash), at this time, you get a NSdata data, convert it to dic, to parse the fields. (Each field has a good function agreed with the server, and execute logic according to its function)

 

(11) By monitoring the onNewMessage method, handle the message red dot, vibration, message prompt and other services

(12) Get all the conversations, get the list of all conversations by calling the [timmanager sharedInstance] getConversationList  method. Note: (must be obtained when im logged in, otherwise it will crash). In this project, im login is done by the server. We will get a userSign (Tencent id) after registering and logging in. Before getConversationList, we must judge Whether this userSign is empty.

(13) Once the conversation is obtained, you can use this conversation as a parameter to customize the chat processing after displaying the cell, which is processed according to the type of elem in the elem in TimMessage.

(14) In Tencent's official api, you can do a lot of processing, such as: message has been read, message is deleted, and the ID of the conversation person is obtained. As long as you can think of it, you can obviously find it in the document.

 

 

 

Guess you like

Origin blog.csdn.net/niumanxx/article/details/108535120