NOTE: These sample applications use the Twilio Video 3.x APIs. For examples using our 2.x APIs, please see the 2.x branch. For examples using our 1.x APIs, please see the 1.x branch.
Please see our iOS 13 Migration Guide for the latest information on iOS 13 and iPadOS 13.
Get started with Video on iOS:
- Setup - Get setup
- Quickstart - Run the Quickstart app
- Examples - Run the sample applications
- Setup an Access Token Server - Setup an access token server
- More Documentation - More documentation related to the iOS Video SDK
- Issues & Support - Filing issues and general support
- License
This repository contains example code written in both Objective-C and Swift. The Swift examples use Apple's Swift 4.2 programming language for iOS.
If you haven't used Twilio before, welcome! You'll need to Sign up for a Twilio account first. It's free!
-
Install CocoaPods 1.7.5 or newer.
-
Run
pod install
from the root directory of this project. CocoaPods will installTwilioVideo.framework
and then set up anxcworkspace
. -
Open
VideoQuickStart.xcworkspace
.
Note: You may need to update the CocoaPods Master Spec Repo by running pod repo update master
in order to fetch the latest specs for TwilioVideo.
You can integrate TwilioVideo.framework
manually by following these install instructions.
To get started with the Swift Quickstart application follow these steps:
- Open the
VideoQuickStart
target from theVideoQuickStart.xcworkspace
in Xcode
- Type in an identity and click on "Generate Access Token" from the Testing Tools page.
Note: If you enter the Room Name, then you can restrict this user's access to the specified Room only. Ideally, you want to implement and deploy an Access Token server to generate tokens. You can read more about setting up your own Access Token Server in this section. Read this tutorial to learn more about Access Tokens.
- Paste the token you generated in the earlier step in the
ViewController.swift
.
- Run the Quickstart app on your iOS device or simulator.
-
As in Step 2, generate a new Token for another identity (such as "Bob"). Copy and paste the access token into
ViewController.swift
(replacing the one you used earlier). Build and run the app on a second physical device if you have one, or the iPhone simulator. -
Once you have both apps running, enter an identical Room name (such as "my-cool-room") into both apps, and tap "Connect" to connect to a video Room (you'll be prompted for mic and camera access on the physical device). Once you've connected from both devices, you should see video!
To get started with the Objective-C Quickstart application follow these steps:
- Open the
ObjCVideoQuickstart
target from theVideoQuickStart.xcworkspace
in Xcode
- Type in an identity and click on "Generate Access Token" from the Testing Tools page.
Note: If you enter the Room Name, then you can restrict this user's access to the specified Room only. Ideally, you want to implement and deploy an Access Token server to generate tokens. You can read more about setting up your own Access Token Server in this section. Read this tutorial to learn more about Access Tokens.
- Paste the token you generated in the earlier step in the
ViewController.m
.
- Run the Quickstart app on your iOS device or simulator.
-
As in Step 2, generate a new Token for another identity (such as "Bob"). Copy and paste the access token into
ViewController.m
(replacing the one you used earlier). Build and run the app on a second physical device if you have one, or the iPhone simulator. -
Once you have both apps running, enter an identical Room name (such as "my-cool-room") into both apps, and tap "Connect" to connect to a video Room (you'll be prompted for mic and camera access on the physical device). Once you've connected from both devices, you should see video!
You can use the iOS Simulator that comes with Xcode to do your testing, but local video will not be shared since the Simulator cannot access a camera.
Note: If you have an iOS device, you can now run apps from Xcode on your device without a paid developer account.
You will also find additional examples that provide more advanced use cases of the Video SDK. The currently included examples are as follows:
- AudioDevice - Provide your own means to playback and record audio using a custom
TVIAudioDevice
and CoreAudio. - AudioSink - Access raw audio samples and record them to disk using AVFoundation. Perform live voice recognition using Apple's Speech framework.
- ARKit - Captures augmented reality content with
ARKit
and usesSceneKit
to place objects in the virtual scene. The resulting rendering is previewed locally, and shared in aTVIRoom
via a customTVIVideoSource
source. This app requires Xcode 11 & iOS 11. - AVPlayer - Shows how to use
AVPlayer
to stream Audio & Video content while connected to aTVIRoom
. - CallKit - Shows how to use Twilio Video with the CallKit framework.
- DataTrack - Shows how to use the Data Track APIs for interactive drawing.
- MultiParty - Video conferencing in a Group Room with up to 4 Participants, dominant speaker detection and network quality events.
- ReplayKit - Shows how to use ReplayKit to share the screen, and microphone via
TVIVideoSource
andTVIAudioDevice
. - Screen Capturer - Use a custom
TVIVideoSource
to capture the contents of aWKWebView
.
Using Twilio's Video client within your applications requires an access token. Access Tokens are short-lived credentials that are signed with a Twilio API Key Secret and contain grants which govern the actions the client holding the token is permitted to perform.
If you want to be a little closer to a real environment, you can download one of the video Quickstart server applications - for instance, Video Quickstart: PHP and either run it locally, or install it on a server. You can review a detailed tutorial.
You'll need to gather a couple of configuration options from the Twilio developer console before running it, so read the directions on the Quickstart. You'll copy the config.example.php file to a config.php file, and then add in these credentials:
Credential | Description |
---|---|
Twilio Account SID | Your main Twilio account identifier - find it on your dashboard. |
API Key | Used to authenticate - generate one here. |
API Secret | Used to authenticate - just like the above, you'll get one here. |
Use whatever clever username you would like for the identity. If you enter the Room Name, then you can restrict this users access to the specified Room only. Read this tutorial for more information on Access Tokens.
When you generate an API key pair at the URLs above, your API Secret will only be shown once - make sure to save this in a secure location.
Because we suggest that you run your video chat application on actual iOS device so that you can use the camera on the device, you'll need to provide an externally accessible URL for the app (the iOS simulator will be fine with localhost). Ngrok creates a publicly accessible URL that you can use to send HTTP/HTTPS traffic to a server running on your localhost. Use HTTPS to make web connections that retrieve a Twilio access token.
When you get a URL from ngrok, go ahead and update ViewController.swift
with the new URL. If you go down this path, be sure to follow the directions in the comments in the viewDidLoad()
method at the top of the source file - you will need to uncomment one line, and comment out another. You will also need to update the code if your ngrok URL changes.
For this Quickstart, the Application transport security settings are set to allow arbitrary HTTP loads for testing your app. For production applications, you'll definitely want to retrieve access tokens over HTTPS/SSL.
You can find more documentation on getting started as well as our latest Docs below:
Please file any issues you find here on Github. Please ensure that you are not sharing any Personally Identifiable Information(PII) or sensitive account information (API keys, credentials, etc.) when reporting an issue.
For general inquiries related to the Video SDK you can file a support ticket.