Agora SDK Integration in iOS

Sync real-time applications for video, chat, and more with Agora’s global network.

Pasi rahul
Simform Engineering
4 min readMar 16, 2023

--

In this tutorial, you’ll learn how to create a real-time application where groups of people can connect over a video call and even chat. The idea is to show how real-time messaging with Agora RTM can be used as an orchestration layer to connect users through small breakout channels, where users can create or join an existing video call using the Agora Real-time Communication engine. Even though this tutorial is for iOS (using Swift), the Agora RTM SDK works for almost all supported platforms.

App Flow

The app flow goes as follows:

  • Tap on a “Join” Button
  • Next, you will see multiple users broadcasting their videos on the channel.
  • Now tap on “Host” at the top of the screen to be a broadcaster.
  • At this point, camera and microphone permission will appear.
  • Flip camera (between front/back camera)
  • Toggle the camera on/off
  • Toggle the microphone on/off
  • Toggle the beautify filter, which makes the image smoother and also makes the broadcaster’s voice clearer.

Download the latest Video or Audio SDK from the following links:

Photo by Agora

Prerequisites

  • Agora Developer Account
  • Xcode 11.0 or later
  • iOS device with 13.0 or later
  • A basic understanding of iOS development
  • CocoaPods

Note: If you need to target an earlier version of iOS, you can change how the buttons as created in the provided example project.

Setup

Start by clicking on creating an iOS or macOS project in Xcode.

Xcode having issues downloading large libraries such as the Agora SDK. If any errors are shown, then you can add swift package like this . In Xcode select File > Swift Packages > Reset Package Caches.

CocoaPods

To install the CocoaPod write it in your pod file AgoraUIKit_iOS with the latest released version, and your Podfile should look like this:

The latest AgoraUIKit release when the post is written is v4.0.3

Run pod install, and open the .xcworkspace file to get started.

Add authorization for the app to use the camera and microphone. For this, open the Info.plist file at the root of your Xcode project and then add NSCameraUsageDescription with NSMicrophoneUsageDescription.

For more information on requesting authorization for media capture, check out this article from Apple.

Let’s see how it goes​ :

Adding Video Streaming

If you want an AgoraViewController then simply loads a below feed in your controller and the entire ViewController will look like this:

Grid layout on the left, floating layout on the right

Photo by Agora

That’s all that’s required when we use Agora UIKit in a basic way. However, this is not taken tokens into consideration, and also tokens are required in production apps for security.

Token Integration

Several blogs and repositories are available for understanding tokens; including a 2-Click setup guide, a prebuilt token server in Golang, and information about fetching a token into your Swift app.

You will need to define an AgoraSettings object. Then assign the value in the token URL and then apply the settings object while creating your AgoraVideoViewer object.

Now, whenever you connect to a new channel, it’ll ask for a Boolean fetchToken value, and set that to true:

Summary

Creating a production application using Agora’s network for video calling and Real-time chat is now easier than ever. The same classes and methods will also work for a macOS application.

By heading over to the Advanced Agora UIKit blog, you can unlock the full potential of Agora UIKit for iOS and macOS. Many more customizations and enhancements can be made using this library.

Photo by Agora

Other Resources

Check the the Agora Video Call Quickstart Guide for more information about creating applications using Agora.io SDKs.

I also invite you to join the Agora.io Developer Slack community.

Follow Simform Engineering to keep up with all the latest trends in the development ecosystem.

--

--