Skip to content

A lightweight framework that helps build iOS apps for photos and video capture.

License

Notifications You must be signed in to change notification settings

Woodyjl/MWCamera

Repository files navigation

MWCamera

CI Status Version License Platform

MWCamera is a lightweight framework that helps build powerful camera apps for ios! This framework was also inspired by SwiftyCam ✊🏽.

🎙 Features

  • Easy to use
  • Supports iOS11.2+
  • Image capture
  • Video capture
  • Manual image quality settings
  • Front and back camera
  • Front and rear flash
  • Record while switching cameras
  • Capture Image while recording
  • manual zoom
  • manual focus
  • Background audio support
  • Fully customizable
  • Universal (iPhone & iPad)
  • Simple Swift syntax
  • Lightweight readable codebase

📲 Installation

MWCamera is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MWCamera'

🌚 Example

To run the example project, clone the repo, and run pod install from the Example directory first.

🤓 How to use

Using MWCamera is very straight forward.

🤨📝 Prerequisites

If you didn't know, Apple requires the additon of the NSCameraUsageDescription and NSMicrophoneUsageDescription keys to the info.plist of your application. Example:

<key>NSCameraUsageDescription</key>
<string>To Capture Photos and Videos</string>
<key>NSMicrophoneUsageDescription</key>
<string>To Record Audio</string>

🥳 Getting Started

If you install MWCamera from Cocoapods, be sure to import the module at the top of the file.

import MWCamera

To get started with MWCamera, subclass MWCameraViewController.

class CameraViewController: MWCameraViewController

Then once you handle camera and microphone permissions you can now configure the AVCaptureSession by calling

self.reconfigureSession()

After this feel free to start adding your own config to to the AVCaptureDevice like

if let device = self?.captureDevice {
    do {
        try device.lockForConfiguration()
        if device.isFocusModeSupported(.continuousAutoFocus) {
            device.focusMode = .continuousAutoFocus
        }

        if device.isSmoothAutoFocusSupported {
            device.isSmoothAutoFocusEnabled = true
        }

        if device.isExposureModeSupported(.continuousAutoExposure) {
            device.exposureMode = .continuousAutoExposure
        }

        if device.isWhiteBalanceModeSupported(.continuousAutoWhiteBalance) {
            device.whiteBalanceMode = .continuousAutoWhiteBalance
        }

        if device.isLowLightBoostSupported {
            device.automaticallyEnablesLowLightBoostWhenAvailable = true
        }

        device.unlockForConfiguration()
    } catch {
        print("[mwCamera]: Error locking configuration")
    }
}

Then afterwords call

self.beginSession()

And that's all to get your camera session up and running! 💪🏾

Also self.reconfigureSession() does not add audio input and output. These are added to the session right before recording then removed right after in order mimic features observed in Snapchat/Instagram.

To capture media MWCamera has the following functions

func startRecording() {}

func stopRecording() {}

func cancelRecording() {}

func capturePhoto() {}

To be alerted on what's going on set an MWCameraDelegate. For photo capture notifications MWCamera already implements the AVCapturePhotoCaptureDelegate so you can just override those functions. Please make sure to call super in order keep MWCamera functioning correctly.

One More Thing!

MWCameraButton is a throw in view that makes setting up an instagram/snapchat camera app even easier. Just three lines:

let captureButton = MWCameraButton()
self.register(captureButton)
view.addSubview(captureButton)

📚 Documentation

Coming soon...😅?

📋 Supported OS & SDK Versions

  • iOS 11.2+
  • Swift 4.2+

📬 Next steps

  • Better documentation
  • Smooth zooming from button
  • Less intruisive and tailorable logs
  • AR Examples like Snap/Insta filters
  • iPadOS support?
  • MacOS support?

❤️ Contributing

This is an open source project, so feel free to contribute. How?

  • Open an issue.
  • Send feedback via email.
  • Propose your own fixes, suggestions and open a pull request with the changes.

See all contributors

👨🏽‍💻 Author

woodyjl, woodyjeanlouis@fiitbuds.com

👮🏾‍♀️ License

MIT License

Copyright (c) 2019 woodyjl <woodyjeanlouis@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

MWCamera is available under the MIT license. See the LICENSE file for more info.