Mobile Development 12 min read

Design and Architecture of the 58 IM SDK for Multi‑Platform Mobile Applications

The article details the background, design goals, layered architecture, message flow, UI customization mechanisms, and key class structures of the 58 Group's cross‑platform IM SDK, illustrating how it supports iOS, Android, Web, and H5 with extensible C++ and UIKit components.

58 Tech
58 Tech
58 Tech
Design and Architecture of the 58 IM SDK for Multi‑Platform Mobile Applications

The 58 IM SDK (referred to as "微聊") provides a cross‑platform instant‑messaging solution for 58 Group's products such as 58同城, 安居客, and 招才猫, supporting iOS, Android, Web, and H5.

Background : Numerous business lines require reliable communication between buyers and sellers. Implementing a custom IM solution per app is costly, so the SDK enables rapid integration of core IM features.

Overall Design Goals :

Stable, high‑reliability message transmission.

UI components bundled in the SDK with customization support.

Rich‑media sending capabilities.

Separation of the message‑transport layer from UI‑related functionality, allowing developers to use either layer independently.

The resulting architecture follows a classic MVC pattern and consists of four layers:

Name

Description

C++ Net

Handles long‑connection logic such as login, logout, kick‑out, push messages, and heartbeats.

C++ Biz

Manages data logic for sessions, messages, user profiles, contacts, groups, and persistence; it is cross‑platform for mobile and desktop.

Lib Layer

Provides a platform‑agnostic interface for upper layers.

UIKit Layer

Renders UI, processes events, and implements IM business logic like pagination, offline message fetching, and user sync.

Key Design Points

Message Sending Flow : Supports text, rich media, audio/video, images, attachments, location, and interactive cards via a unified send API (illustrated in the original diagram).

Message Receiving Flow :

Online reception dispatches data to a dedicated thread for parsing and I/O, then invokes business callbacks for UI updates.

Offline reception uses push; the SDK synchronizes the latest push message per conversation and fetches missing messages when a chat page opens.

Customizable UI : To reduce duplicated UI work, the SDK offers a Lib layer, a UIKit layer, and a Logic layer. The original UIKit layer was refactored into a Logic + UIKit architecture, decoupling UI from SDK internals.

Component Overview

ChatVirtualView : Virtual view for the chat page handling interactions, maintaining a TableView supplied by the host app.

ChatViewModel : Provides data logic for the chat UI (message source, read status, deletion, etc.).

TalkVirtualView : Virtual view for the conversation list with similar responsibilities.

TalkViewModel : Handles data logic for the conversation list.

Conversation List Customization :

The entry point is WChatConversationListController , which holds a WIMTalkVirtualView instance (named vv ) and implements WIMTalkVirtualViewDelegate . Example creation code:

self.vv = [[WIMTalkVirtualView alloc] initWithTableView:self.conversationListTableView];
self.vv.delegate = self;

Delegate methods include cell creation, selection handling, and row‑height calculation, e.g.:

- (UITableViewCell *)tableViewCellForConversationVM:(WIMTalkVirtualView *)vvtableView:(UITableView *)tableview model:(id)model atIndexPath:(NSIndexPath *)indexPath;
- (void)conversationVM:(WIMTalkVirtualView *)vv didSelectConversation:(id)conversation;
- (CGFloat)calculateModelHeight:(GmacsConversationModel *)model;

Message List Customization :

The entry point is WChatConversationController , which contains a WIMChatVirtualView instance ( vv ) and adopts WIMChatVirtualViewTableViewDelegate and WIMChatVirtualViewCommonDelegate . Example creation code:

self.vv = [[WIMChatVirtualView alloc] initWithTableView:self.messageTableView startMessageLocalId:self.startMessageLocalId targetId:targetId targetSource:targetSource conversationType:conversationType];
self.vv.tableViewDelegate = self;
self.vv.commonDelegate = self;

Key delegate implementations (simplified):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath messageModel:(id)model { /* custom cell */ }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath messageModel:(id)model { /* height */ }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath messageModel:(id)model { /* selection */ }

Common delegate methods handle loading animations and error callbacks, e.g.:

- (void)startLoadBackwardsAnimation { /* show loading */ }
- (void)onLoadBackwardsFinished:(NSInteger)errorCode errorMsg:(NSString *)errorMsg { /* handle result */ }

Conclusion : The 58 IM SDK architecture demonstrates a scalable, extensible, and cross‑platform design that isolates business logic from UI, supports rich media, and meets stringent requirements for reliability, customizability, and low iteration cost across multiple business lines.

iOSAndroidC++UI customizationmobile architectureIM SDK
58 Tech
Written by

58 Tech

Official tech channel of 58, a platform for tech innovation, sharing, and communication.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.