User Management
Before opening chat in SDK, a user must be set for whom to open the chat. There may also be a need to remove this user, for example, when user resets registration in the application.
Several methods are available in SDK for user setup and management:
User Setup
Method to set chat user in ChatCenterUI SDK:
func authorize(user: ChatUser, auth: ChatAuth = ChatAuth())
Called before opening chat screen, when user becomes known in parent application (e.g., after entering PIN code in banking app).
Parameters:
user:ChatUserobject containing user information (required parameter)auth: Authorization settings (if using custom method, discussed during integration)
Usage example:
// Create user model
let chatUser = ChatUser(identifier: "user_uuid",
name: "Ivan Ivanov",
data: ["email": "ivan.ivanov@example.ru"])
// Set user in SDK
chatCenterSDK.authorize(user: chatUser)
User Logout
In case of user resetting registration in the application, logout must also be called in SDK (e.g., to unsubscribe from new message notifications in chat). To do this, call method:
func logout() throws
Performs user logout from SDK, clearing current session data. After calling this method, re-authorization (via authorize) will be required to open chat.
Throws: Errors if problem occurs during logout.
Usage example:
do {
try chatCenterSDK?.logout()
// User successfully logged out
} catch {
print("Logout error: \(error)")
}
User Removal
If local user removal is necessary (e.g., user exits authorization zone to PIN code entry screen), use method:
func deauthorizeUser()
It removes current active user and closes server connections. In this case, there will be no SDK requests to server until next authorization. Before reopening chat, a new user must be authorized via authorize method.
Usage example:
chatCenterSDK?.deauthorizeUser()