Events overview
Register OpenIM iOS SDK listeners and synchronize connection and data state with the application lifecycle.
The OpenIM iOS SDK defines listener protocols segmented by functional domain. Add and remove listeners through [OIMManager callbacker]. Retain a strong reference to each listener instance within your application state management layer, as OIMCallbacker maintains only weak references to registered delegates.
Registration lifecycle
| Event scope | Protocol | Related documentation |
|---|---|---|
| Connection and token | Connection callbacks passed during initialization | Authenticate and manage the session |
| User, friend, and blacklist | OIMUserListener, OIMFriendshipListener | User overview |
| Conversations and synchronization | OIMConversationListener | Retrieve the conversation list |
| Conversation groups | Open_im_sdk_callbackOnConversationGroupListener | Conversation groups overview |
| Groups and group members | OIMGroupListener | Group overview |
| Messages | OIMAdvancedMsgListener | Receive messages |
| Custom business notifications | OIMCustomBusinessListener | Receive custom business messages |
| Audio and video calls | OIMSignalingListener | Handle call events |
Register application-level listeners after initSDKWithConfig:... succeeds and prior to initiating login:token:.... Avoid re-registering listeners on view transition or rendering cycles. When logging out, switching user accounts, or tearing down the state controller, invoke the matching remove...Listener: method with the retained listener instance.
Conversation group events follow a dedicated mechanism: OpenIMCore configures a single Open_im_sdk_callbackOnConversationGroupListener via Open_im_sdkSetConversationGroupListenerEnterprise. It bypasses [OIMManager callbacker] and cannot be registered incrementally. Retain this callback object within the conversation manager for the duration of the session and configure it once during startup. Refer to Conversation groups overview for detailed JSON payloads and callback contracts.
Listen for initial synchronization
Data synchronization lifecycle callbacks reside within the OIMConversationListener protocol. Implement the four core synchronization methods to track server state synchronization:
Code example
@interface SDKSyncStore () <OIMConversationListener>
@end
@implementation SDKSyncStore
- (void)startListening {
[[OIMManager callbacker] addConversationListener:self];
}
- (void)stopListening {
[[OIMManager callbacker] removeConversationListener:self];
}
- (void)onSyncServerStart:(BOOL)reInstall {
[self setSyncingWithProgress:0 reInstall:reInstall];
}
- (void)onSyncServerProgress:(NSInteger)progress {
[self setSyncingWithProgress:progress reInstall:self.reInstallSync];
}
- (void)onSyncServerFinish:(BOOL)reInstall {
[self setSyncReadyWithReInstall:reInstall];
[self reloadVisibleSnapshots];
}
- (void)onSyncServerFailed:(BOOL)reInstall {
[self setSyncFailedWithReInstall:reInstall];
}
@endWhen reInstall evaluates to YES, synchronization follows a local database rebuild, indicating that complete state restoration is underway. Track synchronization progress with onSyncServerProgress:. Once synchronization finishes, re-query initial data snapshots required by visible views, and subsequently process incremental updates dispatched by domain listeners.
Synchronization events operate independently of query API callbacks and carry no business entity merge keys. Process synchronization completion, query snapshot fetching, and subsequent real-time event merges as distinct operational phases, scoping data strictly by user account.
Was this page helpful?