This guide uses the Swift Components library for the easiest way to get started on iOS.
LiveKit also supports macOS, tvOS, and visionOS. More documentation for the core Swift SDK is on GitHub.
1. Install LiveKit SDK
let package = Package(...dependencies: [.package(url: "https://github.com/livekit/client-sdk-swift.git", from: "2.0.14"), // Core SDK.package(url: "https://github.com/livekit/components-swift.git", from: "0.1.0"), // UI Components],targets: [.target(name: "MyApp",dependencies: [.product(name: "LiveKitComponents", package: "components-swift"),])])
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 LiveKitimport LiveKitComponentsimport SwiftUI@mainstruct ComponentsExampleApp: App {var body: some Scene {WindowGroup {RoomScope(url: wsURL, token: token, connect: true, enableCamera: true) {LazyVStack {ForEachParticipant { _ inVStack {ForEachTrack(filter: .video) { trackReference inVideoTrackView(trackReference: trackReference).frame(width: 500, height: 500)}}}}}}}}
For more details, you can reference the components example app.
4. Next Steps
- Set up a server to generate tokens for your app at runtime by following this guide: Generating Tokens.
- Visit the GitHub repository for more documentation and examples.
Happy coding!