Agora provides an open-source OpenLive-iOS-Swift sample project on GitHub. This document introduces how to run this project and experience a live video streaming implemented by the Agora SDK.
Create a project in Agora Console, as follows:
Log in to Console, and click in the left navigation menu to enter the Project Management page.
Click Create.
Enter your project name, and select Secure mode: APP ID + Token for the authentication mechanism in the pop-up window.
Click Submit. You can see the created project on the Project Management page.
Agora automatically assigns each project an App ID as a unique identifier.
To copy this App ID, find your project on the Project Management page in Agora Console, and click the eye icon to the right of the App ID.
To ensure communication security, Agora uses tokens (dynamic keys) to authenticate users joining a channel.
Agora Console supports generating temporary tokens for testing purposes.
On the Project Management page, find your project, and click to open the Token page.
Enter a channel name, and click Generate Temp Token to get a temporary token. When joining the channel, ensure that the channel name is the same with the one that you use to generate the temporary token.
Download the Basic-Video-Broadcasting repository, and find the OpenLive-iOS
sample project.
Fill in the OpenLive/KeyCenter.swift
file with the App ID and temporary token generated in Agora Console.
struct KeyCenter {
// Replace #Your App Id# with your App ID, and add quotation marks around it, such as "xxxxxx"
static let AppId: String = <#Your App Id#>
// Replace #Temp Access Token# with your temporary Token, and add quotation marks around it, such as "xxxxxx"
static var Token: String? = <#Temp Access Token#>
}
Integrate the Agora iOS SDK into the sample project, as follows:
libs
folder to the OpenLive
folder.test
, and click Start Live Broadcast
. You will see the following screen on the iOS device:Now you can experience an interactive live video streaming. You can also use the Agora Web sample app to interact with your iOS device. Ensure that you enter the same App ID, channel name, and temporary token in the Agora Web sample app.
The following table lists the structure of the sample project for your reference:
File/Folder | Description |
---|---|
RoomViewController.swift | The code of the main functions and the UI after joining a channel. |
KeyCenter.swift | The code for configuring the App ID and the token. |
MainViewController.swift | The code of the UI before joining a channel. |
Apart from Swift, Agora provides an additional OpenLive-iOS-Objective-C sample project in Objective-C.