Getting started with Agora + iOS

Ashok
3 min readJun 3, 2021

Writing, posting your thoughts in the social media was getting older day by day. Everything moving to instant voice. Means, audio chats becoming trendy now. We have some social media examples like, Facebook’s Rooms, Twitter’s Spaces, Telegram’s voice chats, Clubhouse etc. Yeah! My today’s topic on voice chat iOS app using Agora client. Let’s check it out!

My creation

Create Agora account:

  1. Go to agora.io
  2. Sign up

Create new Agora project:

New agora project setup

Once project created, you have your own app id. Save it somewhere. Need it later. Thats all here.

Life is seems to be sooo simple ! 😆

Xcode project setup:

  1. Create xcode project

2. Add your team and enable automatic sign in.

3. In info.plist file, add the followings:

<key>NSMicrophoneUsageDescription</key>
<string>We need you permission</string>

Note: I recommended you to test the entire app in real device. Not in simulator. Things might be break.

Pods installation — Adding Agora’s iOS SDK:

Open xcode project path in terminal,

pod init
open podfile

In the podfile, add couple of pods and save it.

pod 'AgoraRtm_iOS', '~> 1.4'
pod 'AgoraAudio_iOS', '~> 3.2'

In the terminal,

pod install

Do some UI works:

Keep in mind that you will have two roles : Speaker or Broadcaster and Audience or Listener. They can create, join, leave and destroy channels or rooms. Channels — Its a room or group for voice chat with unique id. Let us meet after your UI works was done. 👷

Initiate Agora Engine:

We need to initiate agora engine first with your agora project app ID that we created in the agora console.

var agoraRTMkit = AgoraRtmKit(appId: "YOUR_APP_ID", delegate: self)
var agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: "YOUR_APP_ID", delegate: self)

Enable specifications:

You can enable agoraKit audio and volume and set channel profile to “liveBroadcasting

agoraKit?.enableAudio()
agoraKit?.enableAudioVolumeIndication(1000, smooth: 3, report_vad: true)
agoraKit?.setChannelProfile(.liveBroadcasting)

Connect channel:

To connect channels, we need to login into the agoraRtmKit with your username.

agoraRTMkit?.login(byToken: "token", user: "USER_NAME")

Note: Here token is optional. Its required for authentication purpose. We are not focusing this.

Create channel:

The createChannel method initiated with unique channel ID/Name.

var agoraRTMchannel = agoraRTMkit?.createChannel(withId: "CHANNEL_NAME", delegate: self)

Join channel:

Once channel created, we need to join in the channel. There are two roles, Speaker and Audience. To set the role, use the following

agoraKit?.setClientRole(userRole)

To join channel,

agoraKit?.joinChannel( byToken: “token”, channelId: “CHANNEL_NAME”, info: nil, uid: nil, joinSuccess: { (_, uid, elapsed) in 
print(uid)
agoraRTMchannel?.join(completion: { (errcode) in
print(errcode)
})
})

Leave channel:

We need to leave the joined channels from agoraKit and agoraRTMchannel.

agoraRTMchannel?.leave()
agoraKit?.createRtcChannel("CHANNEL_NAME")?.leave()
agoraKit?.leaveChannel()

Logout channel:

This is method is used to logout the entire agora engine. To create new channel again, we need to do login and then create channel.

agoraRTMkit?.logout()

Destroy channel:

We need to destroy agora engine first and then agoraRtmkit with channel uniques identifier

AgoraRtcEngineKit.destroy()
agoraRTMkit?.destroyChannel(withId: "CHANNEL_NAME")

Sample app:

I’ve have developed the sample audio chat iOS app. With this, we can create and join rooms.

iVoice app

Here my github link. If you have any doubts, feel free to ask at any time. Follow me on LinkedIN.

Cheers !🍻

--

--

Ashok

 iOS and Flutter developer @TCS, Chennai. Here to share best practices learned through my experience. Reach me on www.linkedin.com/in/ashok1208