Chat / iOS
Chat iOS v4
Chat iOS
Chat
iOS
Home
/
Chat
/
iOS
/
Event delegate
This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.

Add or remove a connection delegate

To detect changes in the connection status of a client app, register a connection delegate ConnectionDelegate with its unique user-defined ID.

If you want to stay informed of changes related to the Sendbird server connection status and notify the changes to different client apps, define and register multiple connection delegates to each view controller.


Connection event types

List of connection events

MethodInvoked whenNotified devices

didConnect(userId:)

The SDK has connected with the given userId.

The device that was connected to the server.

didDisconnect(userId:)

The SDK has disconnected for the userId.

The device that was disconnected from the server.

didStartReconnection

The SDK has started reconnecting to the Sendbird server.

The device where connect(userId:authToken:completionHandler:) was automatically called by the Chat SDK or manually by the client app.

didSucceedReconnection

The SDK has succeeded in reconnecting to the Sendbird server.

The device that successfully reconnected to the server.

didFailReconnection

The SDK has failed to reconnect to the Sendbird server.

The device that failed to reconnect to the server.


Add a connection delegate

The following code shows a full set of supported event callbacks and how to add a connection delegate to the unique SendbirdChat instance.

// CustomViewController.swift
class CustomViewController: UIViewController, ConnectionDelegate {
    func initViewController() {
        SendbirdChat.add(self as ConnectionDelegate, identifier: UNIQUE_DELEGATE_ID)
    }

    func didStartReconnection() { }

    func didSucceedReconnection() { }

    func didFailReconnection() { }

    func didConnect(userId: String) { }

    func didDisconnect(userId: String) { }
}

Remove a connection delegate

The following code shows how to remove the connection delegate.

SendbirdChat.removeConnectionDelegate(forIdentifier: UNIQUE_DELEGATE_ID)