Video Calling App Tutorial using Tokbox

We are going to make an app that will use tokbox to make video calls in swift. So yes your simplest video calling app tutorial using tokbox in iOS. If you need objective-c version of this you can ask question and I’ll be happy to answer it or in comments.

About Tokbox:

With tokbox you can build live interactive video, voice and messaging into your web and mobile apps. It’s simple, mature and easy to implement.

Setting up Tokbox account:

Open Tokbox Signup page and sign up a free trial account. After verifying your email you’ll be on the dashboard which will look something like this:

Tokbox dashboard

In the left side there is a green button “Create my first project” click on that and create your first project by giving it a name. I’m calling it Videotok.


After you finish making the project you’ll be taken to the project where you can see your API key and Secret key. You’ll be using them later in the app.


Open up xCode and make a new single view application, I’ve named my project as “TokboxExample“. To add tokbox library I’m using pods. So just make a pod file and you can paste the following code in to it just make sure the project name is the same as yours.

Next open up Terminal and write the following commands.

It will take sometime to download all the dependancies but it will work. Once it is finished open TokboxExample.xcworkspace

Open ViewController.swift and add import OpenTok

Next we will add delegates which we will be using so edit the line class ViewController: UIViewController  as:

It’ll start showing you an error: Type ‘View Controller’ does not conform to protocol ‘OTPublisherKitDelegate’

error type does not conform to protocol

This is because You need to implement all the required methods of the delegates you have added. So for now just ignore it.

Before viewDidLoad declare three variables:

Making Session ID and Token:

Before making you have to understand that a session is as a room in which participants meet and chat. So for every new call there will be a new session ID.

To make session id you have to go to your account on tokbox and select your project. Scroll down and you’ll find project tools. Select routed and click create session ID. Copy this id and save it in a text file.

making session id on tokbox

Paste this ID in Generate Token‘s Session ID. Make sure Publisher is selected as role give it time and generate the code. Generate and copy this code somewhere too.

generating token for session in tokbox

Making Session for Video Call:

Open ViewController.swift and before viewDidLoad declare three constant:

You guessed it right. Paste the keys in these constants accordingly.

In viewDidLoad add the following:

Now all that is left are the implementation of delegates methods. So copy these methods and paste them after the viewDidLoad ends.

Some of these methods just have print() because they are needed to get rid of that error we were getting earlier. As this is not an advanced tutorial it’ll only let you set up a basic video call session, so I’ve just implemented them and you can add more functionality accordingly to your need.

Lastly open info.plist and add:

Test the app:

You need an iPhone to test this app as the stimulator doesn’t have the camera, so it’ll show you a teapot if you run the code. Run the code on stimulator and then without stopping that select you iPhone and tun the code again. You will see a hotpot on phone but picture on stimulator.

Tags : iosobjective cswifttokboxtutorialvideo call
Chaudhary Talha

The author Chaudhary Talha

I'm an iOS developer by profession and UI/UX designer by passion. All my tutorials are based on my personal experiences and whenever I learn something new I share it with the world.
Like what we are doing? Join Us! Become a contributor at iOS Pakistan.