Browse SDKs · iOS
Platform
SDKsiOS

Integrate for the runtime environment

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

Copy

Runtime environment considerations

The OpenIM iOS SDK exposes the same set of Objective-C APIs across iPhone, iPad, physical devices, and simulators. Variations across environments stem from network endpoint reachability, file storage paths, iOS privacy permissions, and application lifecycle events rather than differences in SDK APIs.

EnvironmentIntegration focus
SimulatorEnsure endpoints are reachable from the host machine simulator. Do not use container-internal loopback addresses.
Physical deviceVerify Wi-Fi, cellular, TLS certificates, background recovery, and iOS system permission prompts.
Objective-C projectDirectly import OpenIMSDK and invoke its public selectors.
Swift projectImport OpenIMSDK via its Clang module; delegate methods follow standard Swift Objective-C bridging conventions.

Configure and initialize the SDK

Initialize the SDK exactly once during the application launch lifecycle. If dataDir is omitted, the SDK defaults to an internal sandbox documents path. Adjust logLevel and isLogStandardOutput to tune logging output.

Parameters

ParameterTypeRequiredDescription
platformOIMPlatformYesTarget client platform type. Specify iPhone for iPhone devices and iPad for iPad devices.
apiAddrNSString *YesOpenIMServer HTTP API base URL.
wsAddrNSString *YesOpenIMServer WebSocket base URL.
dataDirNSString *NoCustom local storage path for client databases and cache. Uses default sandbox directory when omitted.
logLevelNSIntegerNoSDK logging verbosity level. Defaults to 6.
isLogStandardOutputBOOLNoWhether to stream core logs to standard output.

Code example

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];

Return value

The method returns a boolean indicating whether the SDK initialization request was accepted locally. An accepted return value confirms configuration validation only; network communication becomes active upon receiving the onConnectSuccess callback. For production setups, supply retained callback handlers and manage connection states inside an application-level session controller. For full callback definitions, refer to Authenticate and manage the session.

Lifecycle boundaries

  • Do not re-initialize or trigger logins inside individual view controllers. Maintain connection state inside an application-level session manager.
  • View controller appearances or disappearances should register or remove only the delegates scoped to that view; never tear down the SDK on view transitions.
  • When a user logs out, invoke logoutWithOnSuccess:onFailure:. Invoke unInitSDK only when terminating the app process or permanently decommissioning the SDK session.
  • OIMManager automatically subscribes to UIApplicationDidEnterBackgroundNotification, UIApplicationWillEnterForegroundNotification, and system network reachability transitions, synchronizing status with Open_im_sdkSetAppBackgroundStatus and Open_im_sdkNetworkStatusChanged internally.
  • The business UI layer should not duplicate system lifecycle observers or re-invoke low-level Core routines. Manage view transitions, permission requests, and connection banners exclusively.

Verification and troubleshooting

  • Verify reachability of apiAddr, wsAddr, and TLS certificate trust in both the simulator and a physical device.
  • Ensure initSDKWithConfig:... returns YES and wait for onConnectSuccess before triggering business requests.
  • Test connection recovery across offline network switching, app backgrounding, token expiration, and remote kick events.
  • Audit release builds to confirm appropriate log verbosity, local directory sandboxing, and system privacy descriptions.

Next steps