Capture Media

This guide will walk you through capturing images and recording videos using the Truvideo Camera SDK. Whether you're building a full-featured media capture tool or adding basic camera functionality, this SDK simplifies the process with minimal setup.


Prerequisites

Before you start:

  • Make sure the Truvideo Core SDK is integrated.

  • Complete the authentication process. See: Authenticate Guide


Capturing an Image or Video

Follow these steps to configure and launch the Truvideo camera in your app.


Step 1: Get Default Camera Info

Retrieve the default configuration for the device’s camera.

let cameraInfo: TruvideoSdkCameraInformation = TruvideoSdkCamera.camera.getTruvideoSdkCameraInformation()

Step 2: Configure the Camera Settings

Set up the camera’s lens, flash, orientation, and other parameters. The SDK allows both photo and video capture in one session.

let configuration = TruvideoSdkCameraConfiguration(
    lensFacing: .back,
    flashMode: .off,
    orientation: nil,
    outputPath: "",
    frontResolutions: [],
    frontResolution: nil,
    backResolutions: [],
    backResolution: nil,
    mode: .videoAndPicture()
)

Step 3: Launch the Camera View

Use the provided configuration to present the camera interface.

DispatchQueue.main.async {
    viewController.presentTruvideoSdkCameraView(
        preset: configuration,
        onComplete: { cameraResult in
            // Handle the result (image or video)
        }
    )
}

Full Example Function

Here's how everything fits together into a complete Swift function:

import TruvideoSdkCamera

/// Presents the Truvideo Camera with custom configuration.
/// - Parameters:
///   - viewController: The UIViewController or SwiftUIView presenting the camera.
///   - completion: Callback that receives the captured media result.
func cameraInitiate(viewController: UIViewController, _ completion: @escaping (_ cameraResult: TruvideoSdkCameraResult) -> Void) {
    DispatchQueue.main.async {
        // 1. Retrieve default camera information
        let cameraInfo: TruvideoSdkCameraInformation = TruvideoSdkCamera.camera.getTruvideoSdkCameraInformation()
        
        // 2. Create a configuration object
        let configuration = TruvideoSdkCameraConfiguration(
            lensFacing: .back,
            flashMode: .off,
            orientation: nil,
            outputPath: "",
            frontResolutions: [],
            frontResolution: nil,
            backResolutions: [],
            backResolution: nil,
            mode: .videoAndPicture()
        )
        
        // 3. Launch the camera with the configuration
        viewController.presentTruvideoSdkCameraView(
            preset: configuration,
            onComplete: { cameraResult in
                // 4. Handle the camera result (image or video)
                completion(cameraResult)
            }
        )
    }
}

Finali Result -

What’s Next?

Now that you can capture media, you’re ready to:


By following this guide, you’ve enabled rich media capture in your iOS app with just a few lines of code. Let’s keep going!

Last updated

Was this helpful?