Skip to main content
Version 2 of the Swift SDK contains breaking changes from Version 1. This guide will help you migrate your existing application to the latest version.

Overview

The Swift SDK v2 represents a major architectural update with improved performance, better Swift 6 concurrency support, and enhanced API design. While there are breaking changes, most applications can be migrated with straightforward updates.

What’s Changed

Version 2 introduces several significant improvements:

Swift Concurrency

The SDK is now compiled using Swift 6.0 with full support for strict concurrency. Apps compiled in Swift 6 language mode will not need to use @preconcurrency or @unchecked Sendable to access LiveKit classes.

Thread Safety

All core classes can be accessed from any thread (except VideoView, which must be used from the main thread). Delegates will be called on the SDK’s internal thread, so make sure any access to UI elements uses @MainActor or DispatchQueue.main.async.

Memory Management

It is now recommended to use weak var when storing references to SDK-managed objects:
// Use weak references for SDK-managed objects
weak var participant: RemoteParticipant?
weak var publication: TrackPublication?
These objects are invalidated when the Room disconnects and will be released by the SDK. Holding strong references will prevent releasing Room and other internal objects.

API Changes

Connection & Room

The basic connection API remains similar:
let room = Room(delegate: self)

Task {
    do {
        try await room.connect(url: url, token: token)
        
        // Publishing camera & mic
        try await room.localParticipant.setCamera(enabled: true)
        try await room.localParticipant.setMicrophone(enabled: true)
    } catch {
        // Handle error
    }
}

AudioSession Management

Audio session handling has been updated. LiveKit automatically manages AVAudioSession while connected, defaulting to .playback category and switching to .playAndRecord when publishing. To configure manually:
// Disable automatic audio session configuration
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false

CallKit Integration

CallKit integration now requires explicit audio engine availability control:
// Before connecting to a Room
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false
try AudioManager.shared.setEngineAvailability(.none)

// In CXProviderDelegate
func provider(_: CXProvider, didActivate session: AVAudioSession) {
    do {
        try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.mixWithOthers])
        try AudioManager.shared.setEngineAvailability(.default)
    } catch {
        // Handle error
    }
}

func provider(_: CXProvider, didDeactivate _: AVAudioSession) {
    do {
        try AudioManager.shared.setEngineAvailability(.none)
    } catch {
        // Handle error
    }
}

VideoView

The VideoView API remains largely unchanged, but remember that all operations must be performed from the main thread:
DispatchQueue.main.async {
    self.videoView.track = track
}

Migration Checklist

1

Update Dependencies

Update your Package.swift or Xcode project to use version 2.x:
.package(name: "LiveKit", url: "https://github.com/livekit/client-sdk-swift.git", .upToNextMajor("2.12.1"))
2

Update References

Change all strong references to SDK-managed objects to weak references:
// Before
var participant: RemoteParticipant?

// After
weak var participant: RemoteParticipant?
3

Update Delegate Implementations

Ensure all UI updates in delegate methods are dispatched to the main thread:
func room(_: Room, participant _: RemoteParticipant, didSubscribeTrack publication: RemoteTrackPublication) {
    guard let track = publication.track as? VideoTrack else { return }
    DispatchQueue.main.async {
        self.remoteVideoView.track = track
    }
}
4

Review AudioSession Configuration

If you’re using custom audio session configuration or CallKit, update to use the new audio engine availability API.
5

Test Concurrency

If using Swift 6 language mode, verify that all concurrency warnings are resolved.

Additional Resources

Getting Help

If you encounter issues during migration:

Build docs developers (and LLMs) love