Abstract: The most popular SDK should be instant messaging SDK, tried a lot of charges, accidentally found a free instant messaging SDK–MobIM. Compared with other INSTANT messaging SDK access simple, stable background, online technical support, the most important is permanent free.
At present, the most popular SDK should be the INSTANT messaging SDK. After trying many of them are charged, I accidentally found a free INSTANT messaging SDK–MobIM. Compared with other INSTANT messaging SDK access simple, stable background, online technical support, the most important is permanent free.
Now I would like to share this product with you. I think it is a welfare product for developers.
First of all, you need to go to Mob.com to register as a Mob developer, create your own app, and get the registration information such as appkey.
The next step is to register mob in the PList file of your own project.
Here are a few core interface methods:
1. User system mapping
[MobSDK setUserWithUid:@"123" nickName:@" xiao "avatar:@"http://abc.png" userData:nil];Copy the code
2. Send messages (Text messages have been sent as an example, if you want to send pictures, voice, video and other messages, please refer to the official document of Mob in detail, which will not be described here.)
@param text @return Text body instance */ MIMTextMessageBody *body = [MIMTextMessageBody bodyWithText:@" hello "]; @param type Session type @param to appUserId of the receiver for single chat. This parameter is group id@param body message body @return message object */ MIMMessage *message = [MIMMessage messageWithConversationType:MIMConversationTypeSingle to:@"123" body:body]; /** Send a message @param MSG Message object @param completionHandler Completes the callback */ [[MobIM getChatManager] sendMessage:message Completion :^(MIMMessage *message, MIMError *error) {// Completion :^(MIMMessage *message, MIMError *error) { You can display the corresponding message information based on the callback.Copy the code
3. Receiving messages The callback designed in MobIM is basically processed in block form, and the receiving message is also processed in the same way. The receiving message sample code is as follows:
/** @param handlerIdentifier The unique identifier used to receive a message callback. This identifier cannot be an empty or empty string and is used to remove it when it is not needed. Such as: This method is called when you enter the chat interface with someone, and when you return the "chat interface controller" is destroyed (dealloc) the following method is called to remove the listener.@param messageHandler processes the received message block */ [[MobIM GetChatManager] onMessageReceivedWithIdentifier: @ "MobIM" messageHandler: ^ (MIMMessage * message) {NSLog (@ "message is received: %@", message); }];Copy the code
If the listener is not used as a global listener, it is necessary to remove the listener when it is not needed. Example code for removing the listener is as follows:
Remove listener block @param handlerIdentifier block identifier */ [[MobIM getChatManager] removeMessageHandlerForIdentifier:@"MobIM"];Copy the code
Hope to be able to give programmers in need of help ha ~