Agora provides an open-source Agora-iOS-Tutorial-Swift-1to1 sample project on GitHub. This document introduces how to run this project and experience a video call implemented by the Agora SDK.
To create an Agora project, do the following:
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 icon in the App ID column.
To ensure communication security, Agora recommends using tokens to authenticate users joining a channel.
For testing purposes, Agora Console supports generating RTC temporary tokens. To generate an RTC temporary token:
Download the Basic-Video-Call repository, and find the Agora-iOS-Voice-Tutorial-Swift-1to1 sample project.
Fill in the Agora-iOS-Tutorial/AppID.swift
file with the App ID and temporary token generated in Agora Console.
// Replace #Your App Id# with your App ID, and add quotation marks around it, such as "xxxxxx"
let AppID: String = <#Your App ID#>
// Replace #Temp Access Token# with your temporary Token, and add quotation marks, such as "xxxxxx"
let Token: String? = <#Temp Token#>
Open the VideoChatViewController.swift
file, and set channelId
of the joinChannelByToken
method with the channel name that you use to generate the temporary token.
func joinChannel() {
agoraKit.setDefaultAudioRouteToSpeakerphone(true)
// Replace demoChannel1 with the channel name that you use to generate the temporary token
agoraKit.joinChannel(byToken: Token, channelId: "demoChannel1", info: nil, uid: 0) { [unowned self] (channel, uid, elapsed) -> Void in
self.isLocalVideoRender = true
self.logVC?.log(type: .info, content: "did join channel")
}
Integrate the Agora iOS SDK into the sample project, as follows:
libs
folder to the Agora-iOS-Tutorial
folder.Connect your computer to an iOS device, open the sample project on Xcode, and then compile and run the project. If the project runs successfully, you can see the following screen on the iOS device:
Now you can experience a video call. 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 |
---|---|
VideoChatViewController.swift | The code of the main functions and the UI after joining a channel. |
AppID.swift | The code for configuring the App ID and the token. |
Apart from Swift, Agora provides an additional Agora-iOS-Tutorial-Objective-C-1to1 sample project in Objective-C.