Initialize the SDK in Your App

You can use the following code to initialize the chat view.

// Import the SDK
import BotClientUISDK

public class ViewController: UIViewController {

    // Declare a global BotsViewController variable in your app view controller class
    public var chatViewController: BotsViewController?

    override func viewDidLoad() {

        // Obtain a shared instance of BotsViewController from BotsUIManager
        chatViewController = BotsUIManager.shared().viewControllerInstance()

        // Specify the color changes if any in a particular component. Make sure you set all the required colors in BotsProperties before adding the chat view to the view controller.

        // Add the chatViewController to your navigationController
        self.navigationController?.pushViewController(chatViewController!, animated: false)

        // Obtain a shared instance of BotsManager
        let botsManager = BotsManager.shared()

        // If you require access to callback methods provided in AuthenticationProvider. Make sure your class conforms to BotsMessageServiceDelegate
        botsManager.authenticationTokenProvider = self

        // Initialize a BotsConfiguration object and set feature flags if required.
        var botsConfiguration = BotsConfiguration(url: url, userId: userId, channelId: channelId)

        // Initialize the configuration in botsViewController. Make sure you set all the feature flag values before passing the botsConfiguration to initConfiguration.
        chatViewController?.initConfiguration(botsConfiguration: botsConfiguration)

        // If you require access to callback methods provided in BotsMessageServiceDelegate. Make sure your class conforms to BotsMessageServiceDelegate
        botsManager.delegate = self

        // If you require access to callback methods provided in BotsEventListener. Make sure your class conforms to BotsEventListener
        botsManager.botsEventListener = self

        // Initialize and establish connection to the chat server
        botsManager.initialize(botsConfiguration: botsConfiguration, completionHandler: { (connectionStatus, error) in
            if error != nil {
                print ("Error: \(error.localizedDescription)")
            } else {
                print ("Connection Status: \(connectionStatus)")
            }
        })
    }
}