Skip to main content
Version: 5.9.0

App lifecycle integration

Where in the app lifecycle to call SDK methods.

Overall interaction diagram


Integration stages

#StageSDK methodWhen to callDetails
1SDK initializationinit(providerUid:appMarker:chatConfig:loggerConfig:)application(_:didFinishLaunchingWithOptions:)SDK initialization
2APNS token registrationChatCenterUISDK.setDeviceToken(_:)application(_:didRegisterForRemoteNotificationsWithDeviceToken:) (asynchronous system callback, independent of step 1)Notifications
3User authorizationauthorize(user:auth:)After the user enters the authorized zone of the appUser management
4Opening the chattry getChat(userInfo:)present / pushOn user action (e.g., tap on "Support" button). Throws ChatCenterUIError.userNotAuthorized if called before authorizeDisplaying the chat
5User logouttry logout() or deauthorizeUser()logout() — on full account logout (throws ChatCenterUIError.userNotAuthorized if the user is not authorized). deauthorizeUser() — when leaving the authorized zone (e.g., to a PIN code screen); does not throw errorsUser management

Thread safety

The SDK does not guarantee thread safety — call all methods from the main thread. Calling from a background thread may corrupt the SDK's internal state or trigger UIKit warnings.

MethodCalling threadNotes
init(...)Main threadRegisters observers for UIApplication notifications (didBecomeActive, didEnterBackground) and for an internal APNS token change notification — the SDK starts reacting to the app lifecycle and token changes immediately after init
setDeviceToken(_:)Main threadStatic method. Can be called before creating a ChatCenterUISDK instance
authorize(user:auth:)Main threadInitiates REST requests for settings and history. WebSocket opens on the first viewDidAppear of the chat controller; it may open earlier if the server returns registerAtFirstStart
getChat(userInfo:)Main threadReturns a UIViewController — UIKit requires the main thread. Throws ChatCenterUIError.userNotAuthorized
send(message:)Main threadThrows ChatCenterUISendMessageError; see SDK errors
getUnreadMessagesCount(completion:)Main threadThrows ChatCenterUIError.userNotAuthorized. The completion is called on the main thread
logout()Main threadThrows ChatCenterUIError.userNotAuthorized if the user is not authorized or their identifier is empty
deauthorizeUser()Main threadDoes not throw errors
prefill(message:)Main threadStored until the first chat opening; an empty string clears it
handleNotification(userInfo:)Main threadThrows ChatCenterUIError.chatNotOpened if the chat is not open. In the current version, performs no visible actions when the chat is open
ChatCenterUISDKDelegate methodsMain thread (de facto)In the current version, all delegate methods (didChangeUnreadMessages, didReceiveNetwork, didLog, chatCenterUI(chatCenter:didOpen url:) -> Bool — the in-chat link tap handler) are actually delivered on the main thread, but this is not guaranteed by contract. For reliability, wrap UI updates in DispatchQueue.main.async