Swift

VGVoiceClient

Before you can place a call, the Client SDK needs to authenticate to the Vonage servers. The following additions are required to ViewController.swift.

NOTE: Notice that, you have already imported VGVoiceClient at the top of the file.

Add a VGVoiceClient instance, below the callButton.

class ViewController: UIViewController {
    
    var connectionStatusLabel = UILabel()
    var callButton = UIButton(type: .roundedRect)
    let client = VGVoiceClient()
    ...
}

Add the JWT

At the end of viewDidLoad, create a session - make sure to replace ALICE_JWT for the JWT you created during a previous step.

override func viewDidLoad() {
    ...
    VGVoiceClient.isUsingCallKit = false
    let config = VGClientConfig(region: .US)
    config.enableWebsocketInvites = true
    client.setConfig(config)

    client.createSession("ALICE_JWT") { error, sessionId in
        DispatchQueue.main.async { [weak self] in
            guard let self else { return }
            if error == nil {
                self.callButton.alpha = 1
                self.connectionStatusLabel.text = "Connected"
            } else {
                self.connectionStatusLabel.text = error?.localizedDescription
            }
        }
    }
}

NOTE: The enableWebsocketInvites flag on the client configuration and the isUsingCallKit setting should not be used in production. Enable push notifications to make sure you get incoming calls even when your application is in the background using CallKit. See the push notifications guide for more information.

Build and Run

Cmd + R to build and run again:

Interface connected