CameraView

@available(watchOS, unavailable)
@available(visionOS, unavailable)
@MainActor
public struct CameraView : UIViewControllerRepresentable

A SwiftUI view that presents a camera interface for capturing photos and videos.

CameraView wraps UIImagePickerController to provide camera functionality within SwiftUI. It allows users to capture photos and optionally videos from the device camera.

Example usage:

CameraView(onSaveImage: { image in
    // Handle the captured image
}, onSaveVideo: { videoURL in
    // Handle the captured video
})
  • Creates and configures the UIImagePickerController used to capture media.

    Declaration

    Swift

    @MainActor
    public func makeUIViewController(context: Context) -> UIImagePickerController

    Parameters

    context

    The context in which this view controller is created

    Return Value

    A configured UIImagePickerController instance

  • Updates the view controller with any changes to the SwiftUI view’s state.

    This method is required by the UIViewControllerRepresentable protocol but is not used in this implementation.

    Declaration

    Swift

    @MainActor
    public func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context)

    Parameters

    uiViewController

    The view controller to update

    context

    The context in which the view controller exists

  • Creates a coordinator to handle the delegate methods of UIImagePickerController.

    Declaration

    Swift

    @MainActor
    public func makeCoordinator() -> Coordinator

    Return Value

    A new coordinator instance

  • A coordinator class that acts as the delegate for the UIImagePickerController.

    This class handles the events triggered by the image picker, such as when the user captures a photo or video, or cancels the operation.

    See more

    Declaration

    Swift

    @MainActor
    public final class Coordinator : NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate