Compare commits

..

No commits in common. "master" and "feature/Add_changelog" have entirely different histories.

10 changed files with 415 additions and 534 deletions

View File

@ -2,29 +2,8 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## [3.0.0](https://github.com/imaginary-cloud/CameraManager/tree/3.0.0) - 2016-09-16
### Changed
- Syntax update for Swift 3.0.
## [2.2.4](https://github.com/imaginary-cloud/CameraManager/tree/2.2.4) - 2016-07-06
### Added
- Add error checking.
### Changed
- Fixes completion typos and suggests renamed functions.
## [2.2.3](https://github.com/imaginary-cloud/CameraManager/tree/2.2.3) - 2016-05-12
### Changed
- Fixed zoom in StillImage Mode.
- Minor refactoring
## [2.2.2](https://github.com/imaginary-cloud/CameraManager/tree/2.2.2) - 2016-03-07 ## [2.2.2](https://github.com/imaginary-cloud/CameraManager/tree/2.2.2) - 2016-03-07
### Added ### Added
- `CHANGELOG.md` file. - `CHANGELOG.md` file.

View File

@ -1,12 +1,12 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "CameraManager" s.name = "CameraManager"
s.version = "3.0.0" s.version = "2.2.1"
s.summary = "This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. Just drag, drop and use." s.summary = "This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. Just drag, drop and use."
s.requires_arc = true s.requires_arc = true
s.homepage = "https://github.com/imaginary-cloud/CameraManager" s.homepage = "https://github.com/imaginary-cloud/CameraManager"
s.license = 'MIT' s.license = 'MIT'
s.author = { "torrao" => "rtorrao@imaginarycloud.com" } s.author = { "torrao" => "rtorrao@imaginarycloud.com" }
s.source = { :git => "https://github.com/imaginary-cloud/CameraManager.git", :tag => "3.0.0" } s.source = { :git => "https://github.com/imaginary-cloud/CameraManager.git", :tag => "2.2.1" }
s.social_media_url = 'http://www.imaginarycloud.com/' s.social_media_url = 'http://www.imaginarycloud.com/'
s.platform = :ios, '8.0' s.platform = :ios, '8.0'
s.source_files = 'camera/CameraManager.swift' s.source_files = 'camera/CameraManager.swift'

View File

@ -14,20 +14,12 @@ The easiest way to install the CameraManager is with: [CocoaPods](http://cocoapo
### Podfile ### Podfile
If you want Swift 3.0 syntax use:
```ruby
use_frameworks!
pod 'CameraManager', '~> 3.0'
```
If you want Swift 2.0 syntax use: If you want Swift 2.0 syntax use:
```ruby ```ruby
use_frameworks! use_frameworks!
pod 'CameraManager', '~> 2.2' pod 'CameraManager', '~> 2.2
``` ```
If you want Swift 1.2 syntax use: If you want Swift 1.2 syntax use:
@ -60,12 +52,6 @@ let package = Package(
Add the following line to your Cartfile: Add the following line to your Cartfile:
If you want Swift 3.0 syntax use:
```
github "imaginary-cloud/CameraManager" >= 3.0
```
If you want Swift 2.0 syntax use: If you want Swift 2.0 syntax use:
``` ```
@ -81,7 +67,7 @@ github "imaginary-cloud/CameraManager" >= 1.0
And run `carthage update` to build the dynamic framework. And run `carthage update` to build the dynamic framework.
## How to use ## 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 access to it. Have in mind that in order to retain the AVCaptureSession you will need to retain cameraManager instance somewhere, ex. as an instance constant. 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. Have in mind that in order to retain the AVCaptureSession you will need to retain cameraManager instance somewhere, ex. as an instance constant.
```swift ```swift
let cameraManager = CameraManager() let cameraManager = CameraManager()
cameraManager.addPreviewLayerToView(self.cameraView) cameraManager.addPreviewLayerToView(self.cameraView)
@ -155,7 +141,7 @@ cameraManager.showErrorBlock = { (erTitle: String, erMessage: String) -> Void in
To shoot image all you need to do is call: To shoot image all you need to do is call:
```swift ```swift
cameraManager.capturePictureWithCompletion({ (image, error) -> Void in cameraManager.capturePictureWithCompletition({ (image, error) -> Void in
self.myImage = image self.myImage = image
}) })
``` ```
@ -163,7 +149,7 @@ cameraManager.capturePictureWithCompletion({ (image, error) -> Void in
To record video you do: To record video you do:
```swift ```swift
cameraManager.startRecordingVideo() cameraManager.startRecordingVideo()
cameraManager.stopVideoRecording({ (videoURL, error) -> Void in cameraManager.stopRecordingVideo({ (videoURL, error) -> Void in
NSFileManager.defaultManager().copyItemAtURL(videoURL, toURL: self.myVideoURL, error: &error) NSFileManager.defaultManager().copyItemAtURL(videoURL, toURL: self.myVideoURL, error: &error)
}) })
``` ```

View File

@ -201,17 +201,14 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0700; LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0800; LastUpgradeCheck = 0700;
ORGANIZATIONNAME = imaginaryCloud; ORGANIZATIONNAME = imaginaryCloud;
TargetAttributes = { TargetAttributes = {
454C1F4019E82E2500C81915 = { 454C1F4019E82E2500C81915 = {
CreatedOnToolsVersion = 6.0.1; CreatedOnToolsVersion = 6.0.1;
DevelopmentTeam = QM7HJTY23M;
LastSwiftMigration = 0800;
}; };
D71DE8801AD677A7001E62F1 = { D71DE8801AD677A7001E62F1 = {
CreatedOnToolsVersion = 6.3; CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0800;
}; };
}; };
}; };
@ -316,10 +313,8 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = ""; "CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "";
@ -329,7 +324,6 @@
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1", "DEBUG=1",
@ -364,10 +358,8 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@ -375,7 +367,6 @@
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNDECLARED_SELECTOR = YES;
@ -385,7 +376,6 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0; IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
}; };
@ -395,13 +385,11 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = camera/Info.plist; INFOPLIST_FILE = camera/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0; IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = cameraDemo; PRODUCT_BUNDLE_IDENTIFIER = cameraDemo;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
}; };
name = Debug; name = Debug;
}; };
@ -409,20 +397,17 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = camera/Info.plist; INFOPLIST_FILE = camera/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0; IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = cameraDemo; PRODUCT_BUNDLE_IDENTIFIER = cameraDemo;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
}; };
name = Release; name = Release;
}; };
D71DE89B1AD677A8001E62F1 /* Debug */ = { D71DE89B1AD677A8001E62F1 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
@ -441,7 +426,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_BUNDLE_IDENTIFIER = "com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
}; };
@ -450,7 +434,6 @@
D71DE89C1AD677A8001E62F1 /* Release */ = { D71DE89C1AD677A8001E62F1 /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
@ -466,7 +449,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_BUNDLE_IDENTIFIER = "com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = ""; VERSION_INFO_PREFIX = "";
}; };

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0800" LastUpgradeVersion = "0700"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -23,21 +23,21 @@
</BuildActionEntries> </BuildActionEntries>
</BuildAction> </BuildAction>
<TestAction <TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables> <Testables>
</Testables> </Testables>
<AdditionalOptions> <AdditionalOptions>
</AdditionalOptions> </AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal" debugServiceExtension = "internal"
@ -55,10 +55,10 @@
</AdditionalOptions> </AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = "" savedToolIdentifier = ""
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES"> debugDocumentVersioning = "YES">
<MacroExpansion> <MacroExpansion>
<BuildableReference <BuildableReference

View File

@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
return true return true
} }
func applicationWillResignActive(_ application: UIApplication) { func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} }
func applicationDidEnterBackground(_ application: UIApplication) { func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} }
func applicationWillEnterForeground(_ application: UIApplication) { func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} }
func applicationDidBecomeActive(_ application: UIApplication) { func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} }
func applicationWillTerminate(_ application: UIApplication) { func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} }

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ class ImageViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
self.navigationController?.navigationBar.isHidden = false self.navigationController?.navigationBar.hidden = false
if let validImage = self.image { if let validImage = self.image {
self.imageView.image = validImage self.imageView.image = validImage

View File

@ -2,12 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>CameraManager will access your photo library to save pictures/video.</string>
<key>NSMicrophoneUsageDescription</key>
<string>CameraManager will use your microphone to record audio for videos.</string>
<key>NSCameraUsageDescription</key>
<string>CameraManager will use your camera to take pictures/video.</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>

View File

@ -33,32 +33,32 @@ class ViewController: UIViewController {
cameraManager.showAccessPermissionPopupAutomatically = false cameraManager.showAccessPermissionPopupAutomatically = false
askForPermissionsButton.isHidden = true askForPermissionsButton.hidden = true
askForPermissionsLabel.isHidden = true askForPermissionsLabel.hidden = true
let currentCameraState = cameraManager.currentCameraStatus() let currentCameraState = cameraManager.currentCameraStatus()
if currentCameraState == .notDetermined { if currentCameraState == .NotDetermined {
askForPermissionsButton.isHidden = false askForPermissionsButton.hidden = false
askForPermissionsLabel.isHidden = false askForPermissionsLabel.hidden = false
} else if (currentCameraState == .ready) { } else if (currentCameraState == .Ready) {
addCameraToView() addCameraToView()
} }
if !cameraManager.hasFlash { if !cameraManager.hasFlash {
flashModeButton.isEnabled = false flashModeButton.enabled = false
flashModeButton.setTitle("No flash", for: UIControlState()) flashModeButton.setTitle("No flash", forState: UIControlState.Normal)
} }
} }
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
navigationController?.navigationBar.isHidden = true navigationController?.navigationBar.hidden = true
cameraManager.resumeCaptureSession() cameraManager.resumeCaptureSession()
} }
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
cameraManager.stopCaptureSession() cameraManager.stopCaptureSession()
} }
@ -66,95 +66,90 @@ class ViewController: UIViewController {
// MARK: - ViewController // MARK: - ViewController
fileprivate func addCameraToView() private func addCameraToView()
{ {
cameraManager.addPreviewLayerToView(cameraView, newCameraOutputMode: CameraOutputMode.videoWithMic) cameraManager.addPreviewLayerToView(cameraView, newCameraOutputMode: CameraOutputMode.VideoWithMic)
cameraManager.showErrorBlock = { [weak self] (erTitle: String, erMessage: String) -> Void in cameraManager.showErrorBlock = { [weak self] (erTitle: String, erMessage: String) -> Void in
let alertController = UIAlertController(title: erTitle, message: erMessage, preferredStyle: .alert) let alertController = UIAlertController(title: erTitle, message: erMessage, preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { (alertAction) -> Void in })) alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (alertAction) -> Void in }))
self?.present(alertController, animated: true, completion: nil) self?.presentViewController(alertController, animated: true, completion: nil)
} }
} }
// MARK: - @IBActions // MARK: - @IBActions
@IBAction func changeFlashMode(_ sender: UIButton) @IBAction func changeFlashMode(sender: UIButton)
{ {
switch (cameraManager.changeFlashMode()) { switch (cameraManager.changeFlashMode()) {
case .off: case .Off:
sender.setTitle("Flash Off", for: UIControlState()) sender.setTitle("Flash Off", forState: UIControlState.Normal)
case .on: case .On:
sender.setTitle("Flash On", for: UIControlState()) sender.setTitle("Flash On", forState: UIControlState.Normal)
case .auto: case .Auto:
sender.setTitle("Flash Auto", for: UIControlState()) sender.setTitle("Flash Auto", forState: UIControlState.Normal)
} }
} }
@IBAction func recordButtonTapped(_ sender: UIButton) { @IBAction func recordButtonTapped(sender: UIButton) {
switch (cameraManager.cameraOutputMode) { switch (cameraManager.cameraOutputMode) {
case .stillImage: case .StillImage:
cameraManager.capturePictureWithCompletion({ (image, error) -> Void in cameraManager.capturePictureWithCompletition({ (image, error) -> Void in
if let errorOccured = error { let vc: ImageViewController? = self.storyboard?.instantiateViewControllerWithIdentifier("ImageVC") as? ImageViewController
self.cameraManager.showErrorBlock("Error occurred", errorOccured.localizedDescription) if let validVC: ImageViewController = vc {
} if let capturedImage = image {
else { validVC.image = capturedImage
let vc: ImageViewController? = self.storyboard?.instantiateViewController(withIdentifier: "ImageVC") as? ImageViewController self.navigationController?.pushViewController(validVC, animated: true)
if let validVC: ImageViewController = vc {
if let capturedImage = image {
validVC.image = capturedImage
self.navigationController?.pushViewController(validVC, animated: true)
}
} }
} }
}) })
case .videoWithMic, .videoOnly: case .VideoWithMic, .VideoOnly:
sender.isSelected = !sender.isSelected sender.selected = !sender.selected
sender.setTitle(" ", for: UIControlState.selected) sender.setTitle(" ", forState: UIControlState.Selected)
sender.backgroundColor = sender.isSelected ? UIColor.red : UIColor.green sender.backgroundColor = sender.selected ? UIColor.redColor() : UIColor.greenColor()
if sender.isSelected { if sender.selected {
cameraManager.startRecordingVideo() cameraManager.startRecordingVideo()
} else { } else {
cameraManager.stopVideoRecording({ (videoURL, error) -> Void in cameraManager.stopRecordingVideo({ (videoURL, error) -> Void in
if let errorOccured = error { if let errorOccured = error {
self.cameraManager.showErrorBlock("Error occurred", errorOccured.localizedDescription) self.cameraManager.showErrorBlock(erTitle: "Error occurred", erMessage: errorOccured.localizedDescription)
} }
}) })
} }
} }
} }
@IBAction func outputModeButtonTapped(_ sender: UIButton) { @IBAction func outputModeButtonTapped(sender: UIButton) {
cameraManager.cameraOutputMode = cameraManager.cameraOutputMode == CameraOutputMode.videoWithMic ? CameraOutputMode.stillImage : CameraOutputMode.videoWithMic cameraManager.cameraOutputMode = cameraManager.cameraOutputMode == CameraOutputMode.VideoWithMic ? CameraOutputMode.StillImage : CameraOutputMode.VideoWithMic
switch (cameraManager.cameraOutputMode) { switch (cameraManager.cameraOutputMode) {
case .stillImage: case .StillImage:
cameraButton.isSelected = false cameraButton.selected = false
cameraButton.backgroundColor = UIColor.green cameraButton.backgroundColor = UIColor.greenColor()
sender.setTitle("Image", for: UIControlState()) sender.setTitle("Image", forState: UIControlState.Normal)
case .videoWithMic, .videoOnly: case .VideoWithMic, .VideoOnly:
sender.setTitle("Video", for: UIControlState()) sender.setTitle("Video", forState: UIControlState.Normal)
} }
} }
@IBAction func changeCameraDevice(_ sender: UIButton) { @IBAction func changeCameraDevice(sender: UIButton) {
cameraManager.cameraDevice = cameraManager.cameraDevice == CameraDevice.front ? CameraDevice.back : CameraDevice.front cameraManager.cameraDevice = cameraManager.cameraDevice == CameraDevice.Front ? CameraDevice.Back : CameraDevice.Front
switch (cameraManager.cameraDevice) { switch (cameraManager.cameraDevice) {
case .front: case .Front:
sender.setTitle("Front", for: UIControlState()) sender.setTitle("Front", forState: UIControlState.Normal)
case .back: case .Back:
sender.setTitle("Back", for: UIControlState()) sender.setTitle("Back", forState: UIControlState.Normal)
} }
} }
@IBAction func askForCameraPermissions(_ sender: UIButton) { @IBAction func askForCameraPermissions(sender: UIButton) {
cameraManager.askUserForCameraPermission({ permissionGranted in cameraManager.askUserForCameraPermissions({ permissionGranted in
self.askForPermissionsButton.isHidden = true self.askForPermissionsButton.hidden = true
self.askForPermissionsLabel.isHidden = true self.askForPermissionsLabel.hidden = true
self.askForPermissionsButton.alpha = 0 self.askForPermissionsButton.alpha = 0
self.askForPermissionsLabel.alpha = 0 self.askForPermissionsLabel.alpha = 0
if permissionGranted { if permissionGranted {
@ -163,15 +158,15 @@ class ViewController: UIViewController {
}) })
} }
@IBAction func changeCameraQuality(_ sender: UIButton) { @IBAction func changeCameraQuality(sender: UIButton) {
switch (cameraManager.changeQualityMode()) { switch (cameraManager.changeQualityMode()) {
case .high: case .High:
sender.setTitle("High", for: UIControlState()) sender.setTitle("High", forState: UIControlState.Normal)
case .low: case .Low:
sender.setTitle("Low", for: UIControlState()) sender.setTitle("Low", forState: UIControlState.Normal)
case .medium: case .Medium:
sender.setTitle("Medium", for: UIControlState()) sender.setTitle("Medium", forState: UIControlState.Normal)
} }
} }
} }