Skip to content

PTEz/CameraManager

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Camera Manager

CocoaPods Carthage compatible

This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. It follows orientation change and updates UI accordingly, supports front and rear camera selection, different flash modes, inputs and outputs. Just drag, drop and use.

Installation with CocoaPods

The easiest way to install the CameraManager is with: CocoaPods

Podfile

use_frameworks!

pod 'CameraManager', '~> 1.0'

Installation with Carthage

Carthage is another dependency management tool written in Swift.

Add the following line to your Cartfile:

github "imaginary-cloud/CameraManager" >= 1.0

And run carthage update to build the dynamic framework.

How to use

To use it you just add the preview layer to your desired view, you'll get back the state of the camera if it's unavailable, ready or the user denied assess to it.

CameraManager.sharedInstance.addPreviewLayerToView(self.cameraView)

You can set input device to front or back camera:

CameraManager.sharedInstance.cameraDevice = .Front 
CameraManager.sharedInstance.cameraDevice = .Back 

You can set output format to Image, video or video with audio:

CameraManager.sharedInstance.cameraOutputMode = .StillImage
CameraManager.sharedInstance.cameraOutputMode = .VideoWithMic
CameraManager.sharedInstance.cameraOutputMode = .VideoOnly

You can set the quality:

CameraManager.sharedInstance.cameraOutputQuality = .Low
CameraManager.sharedInstance.cameraOutputQuality = .Medium
CameraManager.sharedInstance.cameraOutputQuality = .High

And flash mode (it will also set corresponding torch mode for video shoot):

CameraManager.sharedInstance.flashMode = .Off
CameraManager.sharedInstance.flashMode = .On
CameraManager.sharedInstance.flashMode = .Auto

To check if the device supports flash call:

CameraManager.sharedInstance.hasFlash

To change flash mode to the next available one you can use this handy function which will also return current value for you to update the UI accordingly:

CameraManager.sharedInstance.changeFlashMode()

You can specify if you want to save the files to phone library:

CameraManager.sharedInstance.writeFilesToPhoneLibrary = true

You can specify if you want the user to be asked about camera permissions automatically when you first try to use the camera or manually:

CameraManager.sharedInstance.showAccessPermissionPopupAutomatically = false

You can even setUp your custom block to handle error messages:

CameraManager.sharedInstance.showErrorBlock = { (erTitle: String, erMessage: String) -> Void in
    UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show()
}

To shoot image all you need to do is call:

CameraManager.sharedInstance.capturePictureWithCompletition({ (image, error) -> Void in
	self.myImage = image             
})

To record video you do:

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

Support

Supports iOS 8 and above. Xcode 6.3 is required to build the latest code written in Swift 1.2.

License

Copyright © 2015 ImaginaryCloud, imaginarycloud.com. This library is licensed under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 96.9%
  • Ruby 1.9%
  • C++ 1.2%