MWCamera
is a lightweight framework that helps build powerful camera apps for ios! This framework was also inspired by SwiftyCam ✊🏽.
- Features
- Installation
- Example
- How to use
- Documentation
- Supported OS & SDK Versions
- Next steps
- Contributing
- Author
- License
- 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
MWCamera is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MWCamera'
To run the example project, clone the repo, and run pod install
from the Example directory first.
Using MWCamera is very straight forward.
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>
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)
Coming soon...😅?
- iOS 11.2+
- Swift 4.2+
- Better documentation
- Smooth zooming from button
- Less intruisive and tailorable logs
- AR Examples like Snap/Insta filters
- iPadOS support?
- MacOS support?
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
woodyjl, [email protected]
MIT License
Copyright (c) 2019 woodyjl <[email protected]>
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.