In this example, we will show you how to configure the camera.
License#
All the basic configuration settings are part of the EngineSettings
which are required to initialize the camera.
let settings = EngineSettings(license: secrets.licenseKey, userID: "<your unique user id>")
license
– the license to activate the Engine with.
let settings = EngineSettings(license: secrets.licenseKey,
userID
– an optional unique ID tied to your application’s user. This helps us accurately calculate monthly active users (MAU). Especially useful when one person uses the app on multiple devices with a sign-in feature, ensuring they’re counted once. Providing this aids in better data accuracy. The default value isnil
.
userID: "<your unique user id>")
Configuration#
You can optionally pass a CameraConfiguration
struct to the Camera
initializer.
let config = CameraConfiguration( recordingColor: .blue, highlightColor: .yellow, maxTotalDuration: 30, allowModeSwitching: true)
recordingColor
– the color of the record button.
recordingColor: .blue,
highlightColor
– the highlight color of the delete and confirm buttons.
highlightColor: .yellow,
maxTotalDuration
– the total duration that the camera is allowed to record.
maxTotalDuration: 30,
allowModeSwitching
– Set tofalse
to lock the camera into its initial mode.
allowModeSwitching: true
Mode#
You can optionally configure the initial mode of the camera.
Available Modes#
.standard
: the regular camera..dualCamera(layoutMode)
: records with both front and back camera at the same time.layoutMode
determines the layout of the two cameras. Available options are.horizontal
and.vertical
.
.reaction(layoutMode, URL, positionsSwapped)
: records with the camera while playing back a video.layoutMode
determines the layout of the two cameras. Available options are.horizontal
and.vertical
.URL
the URL to video to record a reaction to.positionsSwapped
a boolean indicating if the video and camera feed should swap positions. By default, the video being reacted to is on the top/left (depending onlayoutMode
).
mode: .standard
Full Code#
Here’s the full code:
import IMGLYCameraimport SwiftUI
struct ConfiguredCameraSolution: View { let settings = EngineSettings(license: secrets.licenseKey, userID: "<your unique user id>")
@State private var isPresented = false
var body: some View { Button("Open the Camera") { isPresented = true } .fullScreenCover(isPresented: $isPresented) { let config = CameraConfiguration( recordingColor: .blue, highlightColor: .yellow, maxTotalDuration: 30, allowModeSwitching: true )
Camera( settings, config: config, mode: .standard ) { result in switch result { case let .success(cameraResult): print(cameraResult) case let .failure(error): print(error.localizedDescription) isPresented = false } } } }}