Swift

Building the call interface

To be able to call, you will need to create a new View Controller for the calling interface. From the Xcode menu, select File > New > File.... Choose a Cocoa Touch Class, name it CallViewController with a subclass of UIViewController and language of Swift.

Xcode adding file

This will create a new file called CallViewController, at the top import VonageClientSDKVoice.

The call interface will need:

  • A UIButton to start a call
  • A UIButton to end a call
  • A UILabel to show status updates

Open CallViewController.swift and add it programmatically.

There are two helper functions setHangUpButtonHidden and setStatusLabelText to avoid repetition of calling DispatchQueue.main.async as changing the state of the UI elements needs to be done on the main thread as required by UIKit. The setHangUpButtonHidden function toggles the visibility of the hangUpButton as this only needs to be visible during an active call.

Presenting the CallViewController

Now that the calling interface is built you will need to present the view controller from the log in screen you built earlier. You will need information about the logged in user and an authenticated client object to be passed between the two view controllers, in CallViewController.swift add the following.

This defines a custom initializer for the class which has a User.type and VGVoiceClient.type as its parameters, which then gets stored in the local user and client properties. Now that you have the user information you can use the callButton to show who the user will be calling, in viewDidLoad add the following.

It sets the title of the view controller and creates a logout button in the navigation bar. Add the corresponding logout function to the end of CallViewController.swift

Now you are ready to present the calling interface along with the user information. To do this you will need to edit the login function in the ViewController.swift file.

If the user connects successfully a CallViewController will be presented with the user data needed.

Build and Run

Run the project again (Cmd + R) to launch it in the simulator. If you log in with one of the users you will see the calling interface

Call interface