Client Setup

Last Edit: Jun 06 2020

Basic setup

Setup Stream API key for the Client in your AppDelegate

Once setupped, you cannot change the API key of StreamChat.

The Client singleton can only be configured once, consecutive configureShared calls will not take affect and will result in an error.

import UIKit
import StreamChatCore

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // This needs to be called only once, since a singleton cannot be configured multiple times!
        Client.configureShared(.init(apiKey: "<#STREAM_API_KEY#>"))
        return true

ℹ️ You can find how to setup a user here.

Connecting & Disconnecting

Client.shared.set(user:token:) acts like login, it'll connect immediately after this call:

Client.shared.set(user: User(id: "john"), token: <#T##Token#>)

Client.shared.disonnect() acts like the logout, it'll clear Client and logout the user. After this call, you should set user again to login & connect:


You do not need to disconnect when app is backgrounded, SDK takes care of background state.

Additional Parameters

1. Enable logs

By default logs are disabled.

You can enable it for requests and/or web socket events with different log levels (.error.debug, .info).

Client.configureShared(.init(apiKey: <#API KEY#>, logOptions: .info))

⚠️ Using .info and .debug levels for production builds are not recommended.

ℹ️ You can find more info about logging you can find here.

2. You can specify a custom Stream BaseURL

Client.configureShared(.init(apiKey: <#API KEY#>, baseURL: .dublin))
// or
Client.configureShared(.init(apiKey: <#API KEY#>, baseURL: "")!)

3. Setup a custom dispatch queue for responses:

Client.configureShared(.init(apiKey: <#API KEY#>, callbackQueue: .global()))

4. App in the background behavior

By default stayConnectedInBackground is true. The Client will try to keep connection when the app went to background to avoid a multiple reconnections. For example, when a user needs temporary switch to another app.

Client.configureShared(.init(apiKey: <#API KEY#>, stayConnectedInBackground: false))