Skip to main content
The Ant Media Server iOS SDK enables ultra-low latency WebRTC streaming in native iOS applications. Built with Swift/Objective-C compatibility and optimized for iPhone and iPad.

Installation

CocoaPods

Add to your Podfile:
pod 'AntMediaSDK', '~> 2.9.0'
Then run:
pod install

Swift Package Manager

Add the package in Xcode:
  1. Go to File > Add Packages
  2. Enter the repository URL: https://github.com/ant-media/WebRTC-iOS-SDK
  3. Select version and add to your project

Manual Installation

  1. Download the latest release from GitHub
  2. Add AntMediaSDK.framework to your project
  3. Link the framework in your target settings

Configuration

Info.plist Permissions

Add required permissions to your Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera access is required for video streaming</string>

<key>NSMicrophoneUsageDescription</key>
<string>Microphone access is required for audio streaming</string>

Background Modes

Enable background audio if needed:
<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
</array>

Basic Usage

Initialize the SDK

import AntMediaSDK

class ViewController: UIViewController {
    var client: AntMediaClient!
    let serverUrl = "wss://your-server:5443/WebRTCAppEE/websocket"
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Initialize client
        client = AntMediaClient.init()
        client.delegate = self
        client.setOptions(url: serverUrl, streamId: "stream1", token: "")
        client.setWebSocketServerUrl(url: serverUrl)
    }
}

// Implement delegate
extension ViewController: AntMediaClientDelegate {
    func clientDidConnect(_ client: AntMediaClient) {
        print("Connected to server")
    }
    
    func clientDidDisconnect(_ client: AntMediaClient) {
        print("Disconnected from server")
    }
    
    func clientHasError(_ client: AntMediaClient, message: String) {
        print("Error: \(message)")
    }
}

Publishing a Stream

Publish video from the device camera:
// Set local video view
client.setLocalView(view: localVideoView)

// Start publishing
let streamId = "myStream123"
client.publish(streamId: streamId)

// Publish with token
let token = "your-publish-token"
client.publish(streamId: streamId, token: token)

// Stop publishing
client.stop()

Playing a Stream

Play an existing stream:
// Set remote video view
client.setRemoteView(view: remoteVideoView)

// Start playing
let streamId = "myStream123"
client.play(streamId: streamId)

// Play with token
let token = "your-play-token"
client.play(streamId: streamId, token: token)

// Stop playing
client.stop()

Video Rendering

Add video views to your interface:
import UIKit

class ViewController: UIViewController {
    let localVideoView: UIView = {
        let view = UIView()
        view.backgroundColor = .black
        return view
    }()
    
    let remoteVideoView: UIView = {
        let view = UIView()
        view.backgroundColor = .black
        return view
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Add video views to your layout
        view.addSubview(localVideoView)
        view.addSubview(remoteVideoView)
        
        // Set constraints...
        
        // Set views in client
        client.setLocalView(view: localVideoView)
        client.setRemoteView(view: remoteVideoView)
    }
}

Conference Room

Join a multi-party conference room:
let roomId = "conference-room-1"
client.joinRoom(roomId: roomId)

// Handle room events in delegate
func roomJoined(roomId: String) {
    print("Joined room: \(roomId)")
}

func streamJoinedRoom(streamId: String) {
    print("Stream joined: \(streamId)")
    client.play(streamId: streamId)
}

// Leave room
client.leaveFromRoom(roomId: roomId)

Camera Controls

Control camera and media:
// Switch between front and back camera
client.switchCamera()

// Toggle video on/off
client.toggleVideo()

// Toggle audio on/off
client.toggleAudio()

// Mute/unmute microphone
client.muteAudio(true)

// Enable/disable video
client.enableVideo(true)

Data Channels

Send and receive real-time data:
// Send data
let message = "Hello viewers!"
client.sendData(message, streamId: streamId)

// Receive data in delegate
func dataReceivedFromDataChannel(_ data: Data, streamId: String) {
    if let message = String(data: data, encoding: .utf8) {
        print("Received: \(message)")
    }
}

Delegate Methods

Implement all delegate methods:
protocol AntMediaClientDelegate: AnyObject {
    func clientDidConnect(_ client: AntMediaClient)
    func clientDidDisconnect(_ client: AntMediaClient)
    func clientHasError(_ client: AntMediaClient, message: String)
    func publishStarted(streamId: String)
    func publishFinished(streamId: String)
    func playStarted(streamId: String)
    func playFinished(streamId: String)
    func disconnected(streamId: String)
    func dataReceivedFromDataChannel(_ data: Data, streamId: String)
    func roomJoined(roomId: String)
    func streamJoinedRoom(streamId: String)
    func streamLeftRoom(streamId: String)
}

Configuration Options

Video Resolution

client.setVideoResolution(width: 1280, height: 720)

Audio/Video Settings

// Set target bitrate
client.setTargetBitrate(videoBitrate: 2000)

// Set max bitrate
client.setMaxBitrate(videoBitrate: 3000)

Resources

iOS SDK Repository

View source code, sample apps, and contribute on GitHub

Requirements

  • iOS 12.0 or later
  • Xcode 13.0 or later
  • Swift 5.5+ or Objective-C
  • Camera and microphone hardware
  • Ant Media Server with SSL/TLS configured
WebRTC requires HTTPS in production. Make sure your Ant Media Server has a valid SSL certificate.

Next Steps

Android SDK

Build for Android with the native Android SDK

Authentication

Secure streams with token authentication

Build docs developers (and LLMs) love