Skip to content

Integration

Tomasz K. edited this page Dec 12, 2024 · 35 revisions

Gdy cię mają wie­szać, pop­roś o szklankę wo­dy. Nig­dy nie wiado­mo, co się wydarzy, zanim przy­niosą.

Introduction

This page is an introduction to the integration of MijickCamera into your application. All code examples presented in this wiki are based on iOS and omit trivial things that might distract you from the core of the topic. However, it should not be too difficult to adapt this code into a working version.

MCamera is a view object that contains three screens that are displayed in relation to the state of the camera:

  • ErrorScreen, which is shown when the user denies any of the required permissions,
  • CapturedMediaScreen, which is presented when the user captures either an image or video (can be disabled),
  • CameraScreen, which contains all of the camera controls that the user can interact with to adjust and capture images or video.

We shall discuss all the methods and ways of customizing MCamera in the following pages (you can find links to them at the bottom of this page), but for now I'd like to introduce you to the simplest way of implementing MCamera in your application.

Integrating MCamera

  1. The first step is to place the MCamera in the contents of the view (or subview)

    struct ContentView: View {
        var body: some View {
            (...)
            MCamera()
            (...)
        }
    }
  2. Now we'll declare the actions that will be called after user captures video and image

    struct ContentView: View {
        var body: some View {
            (...)
            MCamera()
                .onImageCaptured { image, controller in
                    saveImageInGallery(image)
                    controller.reopenCameraScreen()
                }
                .onVideoCaptured { videoURL, controller in
                    saveVideoInGallery(videoURL)
                    controller.reopenCameraScreen()
                }
            (...)
        }
    }
  3. The only thing left to do is to start the camera session

    struct ContentView: View {
        var body: some View {
            (...)
            MCamera()
                .onImageCaptured { image, controller in
                    saveImageInGallery(image)
                    controller.reopenCameraScreen()
                }
                .onVideoCaptured { videoURL, controller in
                    saveVideoInGallery(videoURL)
                    controller.reopenCameraScreen()
                }
                .startSession()
            (...)
        }
    }

Et voilà! We have just finished integrating MCamera into your application! In the following pages I'll show you how to customize your camera view with MijickCamera.

See also