Agora provides an open-source Agora-iOS-Voice-Tutorial-Swift-1to1 sample project on GitHub. This document introduces how to run this project and experience a voice 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-Audio-Call repository, and find the Agora-iOS-Voice-Tutorial-Swift-1to1
sample project.
Fill in the Agora-iOS-Voice-Tutorial/AppID.swift
file with the Apple 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 around it, such as "xxxxxx"
let Token: String? = <#Temp Access Token#>
Open the VoiceChatViewController.swift
file, and set channelId
of the joinChannelByToken
method with the channel name that you use to generate the temporary token.
func joinChannel() {
// Replace demoChannel with the channel name that you use to generate the temporary token
agoraKit.joinChannel(byToken: Token, channelId: "demoChannel", info:nil, uid:0) {[unowned self] (sid, uid, elapsed) -> Void in
self.agoraKit.setEnableSpeakerphone(true)
UIApplication.shared.isIdleTimerDisabled = true
}
}
Integrate the Agora iOS SDK into the sample project, as follows:
libs
folder to the Agora-iOS-Voice-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 voice 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 |
---|---|
VoiceChatViewController.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. |