Swift Quickstart

Get started with LiveKit on iOS

tip:

This guide uses our Swift Components library for the easiest way to get started on iOS.

We also support macOS, tvOS, and visionOS. More documentation for our core Swift SDK is on GitHub.

1. Install LiveKit SDK

Go to Project Settings > Package Dependencies. Add a new package and enter URL:

https://github.com/livekit/components-swift

See Adding package dependencies to your app for more details.

2. Declare permissions

Camera and microphone usage need to be declared in your Info.plist file.

<dict>
...
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) uses your camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) uses your microphone</string>
...
</dict>

Your application can still run a voice call when it is switched to the background if the background mode is enabled. Select the app target in Xcode, click the Capabilities tab, enable Background Modes, and check Audio, AirPlay, and Picture in Picture.

Your Info.plist should have the following entries:

<dict>
...
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>

3. Join a Room

Note that this example hardcodes a token we generated for you that expires in 2 hours. In a real app, you’ll need your server to generate a token for you.

// !! Note !!
// This sample hardcodes a token which expires in 2 hours.
let wsURL = "<your LiveKit server URL>"
let token = "<generate a token>"
// In production you should generate tokens on your server, and your client
// should request a token from your server.
import LiveKit
import LiveKitComponents
import SwiftUI
@main
struct ComponentsExampleApp: App {
var body: some Scene {
WindowGroup {
RoomScope(url: wsURL, token: token, connect: true, enableCamera: true) {
LazyVStack {
ForEachParticipant { _ in
VStack {
ForEachTrack(filter: .video) { trackReference in
VideoTrackView(trackReference: trackReference)
.frame(width: 500, height: 500)
}
}
}
}
}
}
}
}

For more details, you can reference the components example app.

4. Next Steps

Happy coding!