In mobile video calls, the main issues are lifecycle and token management. Without proper configuration, you get resource leaks, session drops, and wasted licenses. Our experience with 30+ projects using the Agora SDK has led to a reliable approach.
Why Agora SDK is the Best Choice for Video Calls
Agora SDK is a managed real-time video and audio service that handles WebRTC under the hood, its own transport network SD-RTN, adaptive bitrate, and codecs. Compared to raw WebRTC: Agora speeds up video call development by 12x(Agora documentation), but requires proper token management. Correct integration can reduce infrastructure costs by up to 40% by utilizing SD-RTN, saving approximately $300–$500 per month for small teams.
Steps to Integrate Agora SDK
- Create an Agora account and create a project in the console to obtain App ID.
- Generate a token using the Agora Token Builder on your backend.
- Initialize the engine once at app launch (see code examples below).
- Join a channel with the token and channel name.
- Set up local and remote video rendering.
- Handle token renewal via delegate callbacks.
- Test with various scenarios (network drop, incoming call).
Properly Configuring Tokens to Avoid Errors
Agora works with an App ID + Token model. App ID is a public identifier from the console. Token is a short-lived JWT that your backend generates via the Agora Token Builder and passes to the client when joining a channel. The most common production errors are tokenExpired (109) and invalidToken (110). The token has a limited TTL (from 24 hours down to 1 hour). We implement handling via the tokenPrivilegeWillExpire delegate method — get a new token from the backend and call renewToken() without breaking the connection.
A typical mistake: the token is generated with UID 0 on the backend, but after joinChannel the client gets a specific UID from Agora — and then on the next renewToken it passes a token for the wrong UID. Solution: save the UID from didJoinChannel and use it when requesting a new token.
| Scenario | TTL | Recommendation |
|---|---|---|
| Standard | 24 hours | Balance of security and refresh frequency |
| High load | 1 hour | Reduces token compromise risk |
Engine Initialization
Initialize the engine once at app launch:
let config = AgoraRtcEngineConfig() config.appId = "YOUR_APP_ID" agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self) val config = RtcEngineConfig() config.mContext = context config.mAppId = "YOUR_APP_ID" config.mEventHandler = handler rtcEngine = RtcEngine.create(config) Do not recreate the engine for each call. sharedEngine is a singleton; calling it again with the same App ID returns the existing instance. On Android, RtcEngine.create() creates a new instance each time; you must destroy the previous one via RtcEngine.destroy(). Otherwise, native resource leaks appear after 3–5 calls. Use LifecycleObserver to automatically destroy the engine when the activity finishes.
Joining a Channel and Handling Video
let option = AgoraRtcChannelMediaOptions() option.clientRoleType = .broadcaster option.channelProfile = .communication agoraKit.joinChannel( byToken: token, channelId: channelName, uid: 0, mediaOptions: option ) uid: 0 — Agora assigns the UID itself. If you need user binding, pass a deterministic numeric ID (UInt32).
Local video is rendered via AgoraRtcVideoCanvas with setupLocalVideo(). Remote video via setupRemoteVideo() in the didJoinedOfUid delegate method. Important: call setupRemoteVideo() on the main thread, otherwise EXC_BAD_ACCESS occurs with rapid join/leave of participants.
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) { DispatchQueue.main.async { let canvas = AgoraRtcVideoCanvas() canvas.uid = uid canvas.renderMode = .hidden canvas.view = self.remoteVideoView self.agoraKit.setupRemoteVideo(canvas) } } Video Quality Settings
Agora provides AgoraVideoEncoderConfiguration presets and custom parameters:
let config = AgoraVideoEncoderConfiguration( size: CGSize(width: 640, height: 360), frameRate: .fps15, bitrate: AgoraVideoBitrateStandard, orientationMode: .adaptative, mirrorMode: .auto ) agoraKit.setVideoEncoderConfiguration(config) For a mobile app, 360p/15fps is a reasonable balance of quality and battery drain. 720p/30fps for tablets or when quality is critical. 1080p is not suitable for mobile: it consumes a lot of power and resources, and the perceptual difference between 720p and 1080p is negligible.
| Resolution | fps | Bitrate | Battery Load |
|---|---|---|---|
| 360p | 15 | Standard | Low |
| 720p | 30 | Standard | Medium |
| 1080p | 30 | High | High |
Handling Interruptions and Lifecycle
On iOS, AVAudioSession.routeChangeNotification and AVAudioSession.interruptionNotification — Agora SDK handles them automatically with the correct AgoraAudioScenario. The .meeting scenario is optimal for video calls: enables AEC, ANS, AGC.
When an incoming system call occurs, Agora does not pause automatically. We implement via CXCallObserver: when CXCall.hasConnected == true — muteLocalAudioStream(true), when the call ends — unmute.
On Android, without a ForegroundService, Android 8+ will kill the process within 5–10 minutes. We start a ForegroundService at the beginning of a call with a notification. android:foregroundServiceType="camera|microphone" in the manifest is mandatory from Android 14.
What's Included in the Work
- Requirements analysis: number of participants, quality, backend integration, budget.
- Token setup: generation, caching, expiry handling.
- UI implementation: video canvases, controls, virtual background.
- Lifecycle: ForegroundService on Android, CXCallObserver on iOS.
- Testing: 10+ scenarios (network drop, incoming call, fast reconnection).
- Documentation: README, code comments, token flow diagram.
- Access to source code and a training session for your team.
- Support: 2 weeks post-release, bug fixes.
Timelines and Cost
Basic integration (1-on-1 video call with camera control, mute, flip) — 3–5 days. With group support up to 8 participants, token management, and background mode — 1–2 weeks. Cost is determined after requirements analysis. Contact us to evaluate your project — we will provide an estimate and roadmap. Get a consultation on Agora integration or order video call implementation.
We are a certified Agora partner with 5 years of experience and 30+ successful projects. Guaranteed uptime and support.







