Camera Manager is a simple Swift class to provide all the configurations you need to create a custom camera view for iOS apps. Learn how we did it and try it out using the link at the end of this article.

UIImagePickerController & AVCaptureSession

When it comes to building an app to take pictures and capture videos in iOS, Apple provides two different approaches: UIImagePickerController
and AVCaptureSession.

UIImagePickerController is the easiest way to get up and running since you can have a working solution with a few lines of code. However, this simplicity comes at a cost: UI customization or adding functionalities to the camera (e.g., tap to focus) has its difficulties.

On the other hand, AVCaptureSession, part of the AVFoundation framework, enables more customization flexibility, but it's harder to configure and manage. Its complexity and known headaches associated with its usage can drive some developers away.

We built Camera Manager to create custom camera views using the best qualities of these tools: better interaction with AVCaptureSession and the flexibility of AVFoundation while hiding all the nitty-gritty details from the developer.

With Camera Manager, the developer can create beautiful custom UIs and achieve awesome results with photos, without reinventing the wheel.

Camera Manager Interface

Camera Manager Interface

Camera Manager provides a simple custom iOS camera view to capture photos and record videos easily, with the following features:

  • front/rear camera selection;
cameraManager.cameraDevice = .Front || .Back
  • tap to focus;
cameraManager.shouldEnableTapToFocus = true || false
  • pinch to zoom;
cameraManager.shouldEnablePinchToZoom = true || false
  • exposure slider;
cameraManager.shouldEnableExposure = true || false
  • flash mode;
cameraManager.flashMode = .Off || .On || .Auto
  • camera quality output;
cameraManager.cameraOutputMode = .StillImage || .VideoWithMic || .VideoOnly
cameraManager.cameraOutputQuality = .Low || .Medium || .High
  • focus mode;
cameraManager.focusMode = .autoFocus || .continuousAutoFocus || .locked
  • exposure mode;
cameraManager.exposureMode = .autoExpose || .continuousAutoExposure || .locked || .custom
  • flip front camera image;
cameraManager.shouldFlipFrontCameraImage = true || false
  • custom album names for image and video;
cameraManager.imageAlbumName =  "Image Album Name" 
cameraManager.videoAlbumName =  "Video Album Name" 
  • EXIF metadata;
  • save location to EXIF.
cameraManager.shouldUseLocationServices = true || false

To provide all these capabilities, Camera Manager uses AVCaptureSession, which according to Apple is: "an object that manages capture activity and coordinates the flow of data from input devices to capture."

AV Capture Session Flow

Instead of manually creating a capture session, obtaining and configuring the necessary capture devices, creating inputs using the capture devices, and configuring a video/photo output object to process captured videos/images, the developer only needs to add the preview layer to the desired view.

let cameraManager = CameraManager()
cameraManager.addPreviewLayerToView(self.cameraView)

All the changes to the AVCaptureDevice, such as setting the flash mode and switching between the front and back cameras, are safely done and configured by Camera Manager.

And then when capturing an image:

cameraManager.capturePictureWithCompletion({ (image, error) -> Void in
    // handle image
})

Also, to start and stop the recording of a video:

cameraManager.startRecordingVideo()
cameraManager.stopVideoRecording({ (videoURL, error) -> Void in
	NSFileManager.defaultManager().copyItemAtURL(videoURL, toURL: self.myVideoURL, error: &error)
})

As demonstrated, Camera Manager provides the flexibility from AVCaptureSession while maintaining the simplicity from UIImagePickerViewController.

Camera Manager Test Photo

There are some alternatives available, but Camera Manager has a few strong points that make it an exceptional choice:

  • It is written in Swift: many of the most used alternatives are written in Objective-C. Given that almost every new app is written in Swift and Apple commits to the language, it makes sense to use Swift to ensure that the app will be way more future-proof.

  • It is highly configurable: Camera Manager gives the developer full control of the functionality needed to build great camera apps.

  • Focus on functionality, not UI: some libraries come bundled with their own UI. Camera Manager focuses on functionality and gives the developer full control to implement the UI as he pleases.

Download Camera Manager

We encourage you to try it. Camera Manager has an example app that you can run on your device. You'll need a real device to run it, due to the use of AVFoundation camera API's which are unavailable on the iOS simulator.

Ready for a UX Audit? Book a free call

Found this article useful? You might like these ones too!