Browse SDKs · iOS
SDKsiOS

Integrate for the runtime environment

Configure and initialize OpenIM SDK across physical devices, simulators, and the iOS application lifecycle.

Copy

Choose the runtime environment

OpenIM iOS SDK uses the same Objective-C APIs on iPhone, iPad, physical devices, and simulators. The main differences between environments are network endpoints, data directories, system permissions, and the application lifecycle, not business APIs.

EnvironmentIntegration focus
SimulatorService endpoints must be reachable from the simulator. Do not use an address that is accessible only inside the server container.
Physical deviceVerify Wi-Fi and mobile networks, TLS certificates, background recovery, and system permissions.
Objective-C projectImport OpenIMSDK directly and call its public selectors.
Swift projectUse the same SDK through its Objective-C module; delegate methods follow automatically bridged names.

Configure and initialize the SDK

Initialize the SDK only once during the application lifecycle. If dataDir is omitted, the SDK uses its default directory. Reduce logging in production and avoid recording tokens.

OIMInitConfig *config = [OIMInitConfig new];
config.platform = iPhone;
config.apiAddr = apiAddr;
config.wsAddr = wsAddr;
config.logLevel = 4;
config.isLogStandardOutput = NO;

BOOL accepted = [[OIMManager manager]
    initSDKWithConfig:config
    onConnecting:nil
    onConnectFailure:nil
    onConnectSuccess:nil
    onKickedOffline:nil
    onUserTokenExpired:nil
    onUserTokenInvalid:nil];

The example uses nil callbacks to focus on runtime configuration. A production application should provide stable callbacks and handle connection state through an application-level session object. accepted means only that the SDK accepted the initialization request; the connection is usable only after onConnectSuccess. For complete connection and token callbacks, see Authenticate and manage the session.

Parameters

FieldTypeDescription
platformOIMPlatformCurrent client platform. Use iPhone for iPhone and iPad for iPad.
apiAddrNSString *OpenIMServer HTTP API endpoint.
wsAddrNSString *OpenIMServer WebSocket endpoint.
dataDirNSString *Optional local data directory.
logLevelNSIntegerSDK log level.
isLogStandardOutputBOOLWhether to output SDK core logs.

Lifecycle boundaries

  • Do not initialize or log in again from every view controller. Keep session state in an application-level object.
  • A view appearing or disappearing should add or remove only the business delegates owned by that view; it should not destroy the SDK.
  • Call logoutWithOnSuccess:onFailure: when the user explicitly logs out. Call unInitSDK only when the application will no longer use the SDK.
  • OIMManager already observes UIApplicationDidEnterBackgroundNotification, UIApplicationWillEnterForegroundNotification, and network reachability changes. It calls Open_im_sdkSetAppBackgroundStatus and Open_im_sdkNetworkStatusChanged internally.
  • The business layer does not need to observe the same system events or call those Core functions again. Duplicate reports make connection recovery and foreground/background state harder to diagnose. The application only needs to manage view tasks, system permissions, and connection-state presentation according to its product logic.

Verify and troubleshoot

  • Verify apiAddr, wsAddr, and TLS certificates in the simulator and on at least one physical device.
  • Confirm that initialization is accepted and that onConnectSuccess arrives before calling business APIs.
  • Test network recovery, foreground/background transitions, token expiration, and forced logout.
  • Verify log levels, the data directory, and privacy permissions in the release configuration.

Next steps