Compare commits
No commits in common. "master" and "2.2.4" have entirely different histories.
23
CHANGELOG.md
23
CHANGELOG.md
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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.4"
|
||||||
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.4" }
|
||||||
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'
|
||||||
|
|
|
||||||
14
README.md
14
README.md
|
|
@ -14,14 +14,6 @@ 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
|
||||||
|
|
@ -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:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -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 = "";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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:.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,57 +8,58 @@
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
import Photos
|
import AssetsLibrary
|
||||||
|
|
||||||
public enum CameraState {
|
public enum CameraState {
|
||||||
case ready, accessDenied, noDeviceFound, notDetermined
|
case Ready, AccessDenied, NoDeviceFound, NotDetermined
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CameraDevice {
|
public enum CameraDevice {
|
||||||
case front, back
|
case Front, Back
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CameraFlashMode: Int {
|
public enum CameraFlashMode: Int {
|
||||||
case off, on, auto
|
case Off, On, Auto
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CameraOutputMode {
|
public enum CameraOutputMode {
|
||||||
case stillImage, videoWithMic, videoOnly
|
case StillImage, VideoWithMic, VideoOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CameraOutputQuality: Int {
|
public enum CameraOutputQuality: Int {
|
||||||
case low, medium, high
|
case Low, Medium, High
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Class for handling iDevices custom camera usage
|
/// Class for handling iDevices custom camera usage
|
||||||
open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGestureRecognizerDelegate {
|
public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGestureRecognizerDelegate {
|
||||||
|
|
||||||
// MARK: - Public properties
|
// MARK: - Public properties
|
||||||
|
|
||||||
/// Capture session to customize camera settings.
|
/// Capture session to customize camera settings.
|
||||||
open var captureSession: AVCaptureSession?
|
public var captureSession: AVCaptureSession?
|
||||||
|
|
||||||
/// Property to determine if the manager should show the error for the user. If you want to show the errors yourself set this to false. If you want to add custom error UI set showErrorBlock property. Default value is false.
|
/// Property to determine if the manager should show the error for the user. If you want to show the errors yourself set this to false. If you want to add custom error UI set showErrorBlock property. Default value is false.
|
||||||
open var showErrorsToUsers = false
|
public var showErrorsToUsers = false
|
||||||
|
|
||||||
/// Property to determine if the manager should show the camera permission popup immediatly when it's needed or you want to show it manually. Default value is true. Be carful cause using the camera requires permission, if you set this value to false and don't ask manually you won't be able to use the camera.
|
/// Property to determine if the manager should show the camera permission popup immediatly when it's needed or you want to show it manually. Default value is true. Be carful cause using the camera requires permission, if you set this value to false and don't ask manually you won't be able to use the camera.
|
||||||
open var showAccessPermissionPopupAutomatically = true
|
public var showAccessPermissionPopupAutomatically = true
|
||||||
|
|
||||||
/// A block creating UI to present error message to the user. This can be customised to be presented on the Window root view controller, or to pass in the viewController which will present the UIAlertController, for example.
|
/// A block creating UI to present error message to the user. This can be customised to be presented on the Window root view controller, or to pass in the viewController which will present the UIAlertController, for example.
|
||||||
open var showErrorBlock:(_ erTitle: String, _ erMessage: String) -> Void = { (erTitle: String, erMessage: String) -> Void in
|
public var showErrorBlock:(erTitle: String, erMessage: String) -> Void = { (erTitle: String, erMessage: String) -> Void in
|
||||||
|
|
||||||
// var alertController = UIAlertController(title: erTitle, message: erMessage, preferredStyle: .Alert)
|
// var 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 }))
|
||||||
//
|
//
|
||||||
// if let topController = UIApplication.sharedApplication().keyWindow?.rootViewController {
|
// if let topController = UIApplication.sharedApplication().keyWindow?.rootViewController {
|
||||||
// topController.presentViewController(alertController, animated: true, completion:nil)
|
// topController.presentViewController(alertController, animated: true, completion:nil)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Property to determine if manager should write the resources to the phone library. Default value is true.
|
/// Property to determine if manager should write the resources to the phone library. Default value is true.
|
||||||
open var writeFilesToPhoneLibrary = true
|
public var writeFilesToPhoneLibrary = true
|
||||||
|
|
||||||
/// Property to determine if manager should follow device orientation. Default value is true.
|
/// Property to determine if manager should follow device orientation. Default value is true.
|
||||||
open var shouldRespondToOrientationChanges = true {
|
public var shouldRespondToOrientationChanges = true {
|
||||||
didSet {
|
didSet {
|
||||||
if shouldRespondToOrientationChanges {
|
if shouldRespondToOrientationChanges {
|
||||||
_startFollowingDeviceOrientation()
|
_startFollowingDeviceOrientation()
|
||||||
|
|
@ -69,18 +70,18 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The Bool property to determine if the camera is ready to use.
|
/// The Bool property to determine if the camera is ready to use.
|
||||||
open var cameraIsReady: Bool {
|
public var cameraIsReady: Bool {
|
||||||
get {
|
get {
|
||||||
return cameraIsSetup
|
return cameraIsSetup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The Bool property to determine if current device has front camera.
|
/// The Bool property to determine if current device has front camera.
|
||||||
open var hasFrontCamera: Bool = {
|
public var hasFrontCamera: Bool = {
|
||||||
let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo)
|
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
|
||||||
for device in devices! {
|
for device in devices {
|
||||||
let captureDevice = device as! AVCaptureDevice
|
let captureDevice = device as! AVCaptureDevice
|
||||||
if (captureDevice.position == .front) {
|
if (captureDevice.position == .Front) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,19 +89,19 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}()
|
}()
|
||||||
|
|
||||||
/// The Bool property to determine if current device has flash.
|
/// The Bool property to determine if current device has flash.
|
||||||
open var hasFlash: Bool = {
|
public var hasFlash: Bool = {
|
||||||
let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo)
|
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
|
||||||
for device in devices! {
|
for device in devices {
|
||||||
let captureDevice = device as! AVCaptureDevice
|
let captureDevice = device as! AVCaptureDevice
|
||||||
if (captureDevice.position == .back) {
|
if (captureDevice.position == .Back) {
|
||||||
return captureDevice.hasFlash
|
return captureDevice.hasFlash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}()
|
}()
|
||||||
|
|
||||||
/// Property to change camera device between front and back.
|
/// Property to change camera device between front and back.
|
||||||
open var cameraDevice = CameraDevice.back {
|
public var cameraDevice = CameraDevice.Back {
|
||||||
didSet {
|
didSet {
|
||||||
if cameraIsSetup {
|
if cameraIsSetup {
|
||||||
if cameraDevice != oldValue {
|
if cameraDevice != oldValue {
|
||||||
|
|
@ -113,7 +114,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Property to change camera flash mode.
|
/// Property to change camera flash mode.
|
||||||
open var flashMode = CameraFlashMode.off {
|
public var flashMode = CameraFlashMode.Off {
|
||||||
didSet {
|
didSet {
|
||||||
if cameraIsSetup {
|
if cameraIsSetup {
|
||||||
if flashMode != oldValue {
|
if flashMode != oldValue {
|
||||||
|
|
@ -124,7 +125,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Property to change camera output quality.
|
/// Property to change camera output quality.
|
||||||
open var cameraOutputQuality = CameraOutputQuality.high {
|
public var cameraOutputQuality = CameraOutputQuality.High {
|
||||||
didSet {
|
didSet {
|
||||||
if cameraIsSetup {
|
if cameraIsSetup {
|
||||||
if cameraOutputQuality != oldValue {
|
if cameraOutputQuality != oldValue {
|
||||||
|
|
@ -135,7 +136,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Property to change camera output.
|
/// Property to change camera output.
|
||||||
open var cameraOutputMode = CameraOutputMode.stillImage {
|
public var cameraOutputMode = CameraOutputMode.StillImage {
|
||||||
didSet {
|
didSet {
|
||||||
if cameraIsSetup {
|
if cameraIsSetup {
|
||||||
if cameraOutputMode != oldValue {
|
if cameraOutputMode != oldValue {
|
||||||
|
|
@ -148,75 +149,80 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Property to check video recording duration when in progress
|
/// Property to check video recording duration when in progress
|
||||||
open var recordedDuration : CMTime { return movieOutput?.recordedDuration ?? kCMTimeZero }
|
public var recordedDuration : CMTime { return movieOutput?.recordedDuration ?? kCMTimeZero }
|
||||||
|
|
||||||
/// Property to check video recording file size when in progress
|
/// Property to check video recording file size when in progress
|
||||||
open var recordedFileSize : Int64 { return movieOutput?.recordedFileSize ?? 0 }
|
public var recordedFileSize : Int64 { return movieOutput?.recordedFileSize ?? 0 }
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Private properties
|
// MARK: - Private properties
|
||||||
|
|
||||||
fileprivate weak var embeddingView: UIView?
|
private weak var embeddingView: UIView?
|
||||||
fileprivate var videoCompletion: ((_ videoURL: URL?, _ error: NSError?) -> Void)?
|
private var videoCompletion: ((videoURL: NSURL?, error: NSError?) -> Void)?
|
||||||
|
|
||||||
fileprivate var sessionQueue: DispatchQueue = DispatchQueue(label: "CameraSessionQueue", attributes: [])
|
private var sessionQueue: dispatch_queue_t = dispatch_queue_create("CameraSessionQueue", DISPATCH_QUEUE_SERIAL)
|
||||||
|
|
||||||
fileprivate lazy var frontCameraDevice: AVCaptureDevice? = {
|
private lazy var frontCameraDevice: AVCaptureDevice? = {
|
||||||
let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) as! [AVCaptureDevice]
|
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice]
|
||||||
return devices.filter{$0.position == .front}.first
|
return devices.filter{$0.position == .Front}.first
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fileprivate lazy var backCameraDevice: AVCaptureDevice? = {
|
private lazy var backCameraDevice: AVCaptureDevice? = {
|
||||||
let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) as! [AVCaptureDevice]
|
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice]
|
||||||
return devices.filter{$0.position == .back}.first
|
return devices.filter{$0.position == .Back}.first
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fileprivate lazy var mic: AVCaptureDevice? = {
|
private lazy var mic: AVCaptureDevice? = {
|
||||||
return AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)
|
return AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fileprivate var stillImageOutput: AVCaptureStillImageOutput?
|
private var stillImageOutput: AVCaptureStillImageOutput?
|
||||||
fileprivate var movieOutput: AVCaptureMovieFileOutput?
|
private var movieOutput: AVCaptureMovieFileOutput?
|
||||||
fileprivate var previewLayer: AVCaptureVideoPreviewLayer?
|
private var previewLayer: AVCaptureVideoPreviewLayer?
|
||||||
fileprivate var library: PHPhotoLibrary?
|
private var library: ALAssetsLibrary?
|
||||||
|
|
||||||
fileprivate var cameraIsSetup = false
|
private var cameraIsSetup = false
|
||||||
fileprivate var cameraIsObservingDeviceOrientation = false
|
private var cameraIsObservingDeviceOrientation = false
|
||||||
|
|
||||||
fileprivate var zoomScale = CGFloat(1.0)
|
private var zoomScale = CGFloat(1.0)
|
||||||
fileprivate var beginZoomScale = CGFloat(1.0)
|
private var beginZoomScale = CGFloat(1.0)
|
||||||
fileprivate var maxZoomScale = CGFloat(1.0)
|
private var maxZoomScale = CGFloat(1.0)
|
||||||
|
|
||||||
fileprivate var tempFilePath: URL = {
|
private var tempFilePath: NSURL = {
|
||||||
let tempPath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("tempMovie").appendingPathExtension("mp4").absoluteString
|
let tempPath = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("tempMovie").URLByAppendingPathExtension("mp4").absoluteString
|
||||||
if FileManager.default.fileExists(atPath: tempPath) {
|
if NSFileManager.defaultManager().fileExistsAtPath(tempPath) {
|
||||||
do {
|
do {
|
||||||
try FileManager.default.removeItem(atPath: tempPath)
|
try NSFileManager.defaultManager().removeItemAtPath(tempPath)
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
return URL(string: tempPath)!
|
return NSURL(string: tempPath)!
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
||||||
// MARK: - CameraManager
|
// MARK: - CameraManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Inits a capture session and adds a preview layer to the given view. Preview layer bounds will automaticaly be set to match given view. Default session is initialized with still image output.
|
Inits a capture session and adds a preview layer to the given view. Preview layer bounds will automaticaly be set to match given view. Default session is initialized with still image output.
|
||||||
|
|
||||||
:param: view The view you want to add the preview layer to
|
:param: view The view you want to add the preview layer to
|
||||||
:param: cameraOutputMode The mode you want capturesession to run image / video / video and microphone
|
:param: cameraOutputMode The mode you want capturesession to run image / video / video and microphone
|
||||||
:param: completion Optional completion block
|
:param: completion Optional completion block
|
||||||
|
|
||||||
:returns: Current state of the camera: Ready / AccessDenied / NoDeviceFound / NotDetermined.
|
:returns: Current state of the camera: Ready / AccessDenied / NoDeviceFound / NotDetermined.
|
||||||
*/
|
*/
|
||||||
open func addPreviewLayerToView(_ view: UIView) -> CameraState {
|
public func addPreviewLayerToView(view: UIView) -> CameraState {
|
||||||
return addPreviewLayerToView(view, newCameraOutputMode: cameraOutputMode)
|
return addPreviewLayerToView(view, newCameraOutputMode: cameraOutputMode)
|
||||||
}
|
}
|
||||||
open func addPreviewLayerToView(_ view: UIView, newCameraOutputMode: CameraOutputMode) -> CameraState {
|
public func addPreviewLayerToView(view: UIView, newCameraOutputMode: CameraOutputMode) -> CameraState {
|
||||||
return addLayerPreviewToView(view, newCameraOutputMode: newCameraOutputMode, completion: nil)
|
return addLayerPreviewToView(view, newCameraOutputMode: newCameraOutputMode, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
open func addLayerPreviewToView(_ view: UIView, newCameraOutputMode: CameraOutputMode, completion: ((Void) -> Void)?) -> CameraState {
|
@available(*, unavailable, renamed="addLayerPreviewToView")
|
||||||
|
public func addPreviewLayerToView(view: UIView, newCameraOutputMode: CameraOutputMode, completition: (Void -> Void)?) -> CameraState {
|
||||||
|
return addLayerPreviewToView(view, newCameraOutputMode: newCameraOutputMode, completion: completition)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func addLayerPreviewToView(view: UIView, newCameraOutputMode: CameraOutputMode, completion: (Void -> Void)?) -> CameraState {
|
||||||
if _canLoadCamera() {
|
if _canLoadCamera() {
|
||||||
if let _ = embeddingView {
|
if let _ = embeddingView {
|
||||||
if let validPreviewLayer = previewLayer {
|
if let validPreviewLayer = previewLayer {
|
||||||
|
|
@ -242,21 +248,24 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
return _checkIfCameraIsAvailable()
|
return _checkIfCameraIsAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@available(*, unavailable, renamed="askUserForCameraPermission")
|
||||||
Asks the user for camera permissions. Only works if the permissions are not yet determined. Note that it'll also automaticaly ask about the microphone permissions if you selected VideoWithMic output.
|
public func askUserForCameraPermissions(completition: Bool -> Void) {}
|
||||||
|
|
||||||
:param: completion Completion block with the result of permission request
|
/**
|
||||||
*/
|
Asks the user for camera permissions. Only works if the permissions are not yet determined. Note that it'll also automaticaly ask about the microphone permissions if you selected VideoWithMic output.
|
||||||
open func askUserForCameraPermission(_ completion: @escaping (Bool) -> Void) {
|
|
||||||
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (alowedAccess) -> Void in
|
:param: completion Completion block with the result of permission request
|
||||||
if self.cameraOutputMode == .videoWithMic {
|
*/
|
||||||
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeAudio, completionHandler: { (alowedAccess) -> Void in
|
public func askUserForCameraPermission(completion: Bool -> Void) {
|
||||||
DispatchQueue.main.sync(execute: { () -> Void in
|
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (alowedAccess) -> Void in
|
||||||
|
if self.cameraOutputMode == .VideoWithMic {
|
||||||
|
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeAudio, completionHandler: { (alowedAccess) -> Void in
|
||||||
|
dispatch_sync(dispatch_get_main_queue(), { () -> Void in
|
||||||
completion(alowedAccess)
|
completion(alowedAccess)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
DispatchQueue.main.sync(execute: { () -> Void in
|
dispatch_sync(dispatch_get_main_queue(), { () -> Void in
|
||||||
completion(alowedAccess)
|
completion(alowedAccess)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -265,19 +274,19 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Stops running capture session but all setup devices, inputs and outputs stay for further reuse.
|
Stops running capture session but all setup devices, inputs and outputs stay for further reuse.
|
||||||
*/
|
*/
|
||||||
open func stopCaptureSession() {
|
public func stopCaptureSession() {
|
||||||
captureSession?.stopRunning()
|
captureSession?.stopRunning()
|
||||||
_stopFollowingDeviceOrientation()
|
_stopFollowingDeviceOrientation()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Resumes capture session.
|
Resumes capture session.
|
||||||
*/
|
*/
|
||||||
open func resumeCaptureSession() {
|
public func resumeCaptureSession() {
|
||||||
if let validCaptureSession = captureSession {
|
if let validCaptureSession = captureSession {
|
||||||
if !validCaptureSession.isRunning && cameraIsSetup {
|
if !validCaptureSession.running && cameraIsSetup {
|
||||||
validCaptureSession.startRunning()
|
validCaptureSession.startRunning()
|
||||||
_startFollowingDeviceOrientation()
|
_startFollowingDeviceOrientation()
|
||||||
}
|
}
|
||||||
|
|
@ -297,11 +306,11 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Stops running capture session and removes all setup devices, inputs and outputs.
|
Stops running capture session and removes all setup devices, inputs and outputs.
|
||||||
*/
|
*/
|
||||||
open func stopAndRemoveCaptureSession() {
|
public func stopAndRemoveCaptureSession() {
|
||||||
stopCaptureSession()
|
stopCaptureSession()
|
||||||
cameraDevice = .back
|
cameraDevice = .Back
|
||||||
cameraIsSetup = false
|
cameraIsSetup = false
|
||||||
previewLayer = nil
|
previewLayer = nil
|
||||||
captureSession = nil
|
captureSession = nil
|
||||||
|
|
@ -312,12 +321,15 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
movieOutput = nil
|
movieOutput = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@available(*, unavailable, renamed="capturePictureWithCompletion")
|
||||||
Captures still image from currently running capture session.
|
public func capturePictureWithCompletition(imageCompletition: (UIImage?, NSError?) -> Void) {}
|
||||||
|
|
||||||
:param: imageCompletion Completion block containing the captured UIImage
|
/**
|
||||||
*/
|
Captures still image from currently running capture session.
|
||||||
open func capturePictureWithCompletion(_ imageCompletion: @escaping (UIImage?, NSError?) -> Void) {
|
|
||||||
|
:param: imageCompletion Completion block containing the captured UIImage
|
||||||
|
*/
|
||||||
|
public func capturePictureWithCompletion(imageCompletion: (UIImage?, NSError?) -> Void) {
|
||||||
self.capturePictureDataWithCompletion { data, error in
|
self.capturePictureDataWithCompletion { data, error in
|
||||||
|
|
||||||
guard error == nil, let imageData = data else {
|
guard error == nil, let imageData = data else {
|
||||||
|
|
@ -327,49 +339,53 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
|
|
||||||
if self.writeFilesToPhoneLibrary == true, let library = self.library {
|
if self.writeFilesToPhoneLibrary == true, let library = self.library {
|
||||||
|
|
||||||
|
library.writeImageDataToSavedPhotosAlbum(imageData, metadata:nil, completionBlock: { picUrl, error in
|
||||||
|
|
||||||
library.performChanges({
|
guard error != nil else {
|
||||||
PHAssetChangeRequest.creationRequestForAsset(from: UIImage(data: imageData)!)
|
return
|
||||||
}, completionHandler: { success, error in
|
}
|
||||||
guard error != nil else {
|
|
||||||
return
|
dispatch_async(dispatch_get_main_queue(), {
|
||||||
}
|
self._show(NSLocalizedString("Error", comment:""), message: error.localizedDescription)
|
||||||
|
})
|
||||||
|
|
||||||
DispatchQueue.main.async(execute: {
|
|
||||||
self._show(NSLocalizedString("Error", comment:""), message: (error?.localizedDescription)!)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
imageCompletion(UIImage(data: imageData), nil)
|
imageCompletion(UIImage(data: imageData), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(*, unavailable, renamed="capturePictureWithCompletion")
|
||||||
|
public func capturePictureDataWithCompletition(imageCompletition: (NSData?, NSError?) -> Void) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Captures still image from currently running capture session.
|
Captures still image from currently running capture session.
|
||||||
|
|
||||||
:param: imageCompletion Completion block containing the captured imageData
|
:param: imageCompletion Completion block containing the captured imageData
|
||||||
*/
|
*/
|
||||||
open func capturePictureDataWithCompletion(_ imageCompletion: @escaping (Data?, NSError?) -> Void) {
|
public func capturePictureDataWithCompletion(imageCompletion: (NSData?, NSError?) -> Void) {
|
||||||
|
|
||||||
guard cameraIsSetup else {
|
guard cameraIsSetup else {
|
||||||
_show(NSLocalizedString("No capture session setup", comment:""), message: NSLocalizedString("I can't take any picture", comment:""))
|
_show(NSLocalizedString("No capture session setup", comment:""), message: NSLocalizedString("I can't take any picture", comment:""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard cameraOutputMode == .stillImage else {
|
guard cameraOutputMode == .StillImage else {
|
||||||
_show(NSLocalizedString("Capture session output mode video", comment:""), message: NSLocalizedString("I can't take any picture", comment:""))
|
_show(NSLocalizedString("Capture session output mode video", comment:""), message: NSLocalizedString("I can't take any picture", comment:""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionQueue.async(execute: {
|
dispatch_async(sessionQueue, {
|
||||||
self._getStillImageOutput().captureStillImageAsynchronously(from: self._getStillImageOutput().connection(withMediaType: AVMediaTypeVideo), completionHandler: { [unowned self] sample, error in
|
self._getStillImageOutput().captureStillImageAsynchronouslyFromConnection(self._getStillImageOutput().connectionWithMediaType(AVMediaTypeVideo), completionHandler: { [unowned self] sample, error in
|
||||||
|
|
||||||
|
|
||||||
guard error == nil else {
|
guard error == nil else {
|
||||||
DispatchQueue.main.async(execute: {
|
dispatch_async(dispatch_get_main_queue(), {
|
||||||
self._show(NSLocalizedString("Error", comment:""), message: (error?.localizedDescription)!)
|
self._show(NSLocalizedString("Error", comment:""), message: error.localizedDescription)
|
||||||
})
|
})
|
||||||
imageCompletion(nil, error as NSError?)
|
imageCompletion(nil, error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -378,28 +394,31 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
|
|
||||||
imageCompletion(imageData, nil)
|
imageCompletion(imageData, nil)
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Starts recording a video with or without voice as in the session preset.
|
Starts recording a video with or without voice as in the session preset.
|
||||||
*/
|
*/
|
||||||
open func startRecordingVideo() {
|
public func startRecordingVideo() {
|
||||||
if cameraOutputMode != .stillImage {
|
if cameraOutputMode != .StillImage {
|
||||||
_getMovieOutput().startRecording(toOutputFileURL: tempFilePath, recordingDelegate: self)
|
_getMovieOutput().startRecordingToOutputFileURL(tempFilePath, recordingDelegate: self)
|
||||||
} else {
|
} else {
|
||||||
_show(NSLocalizedString("Capture session output still image", comment:""), message: NSLocalizedString("I can only take pictures", comment:""))
|
_show(NSLocalizedString("Capture session output still image", comment:""), message: NSLocalizedString("I can only take pictures", comment:""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(*, unavailable, renamed="stopVideoRecording")
|
||||||
|
public func stopRecordingVideo(completition:(videoURL: NSURL?, error: NSError?) -> Void) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Stop recording a video. Save it to the cameraRoll and give back the url.
|
Stop recording a video. Save it to the cameraRoll and give back the url.
|
||||||
*/
|
*/
|
||||||
open func stopVideoRecording(_ completion:((_ videoURL: URL?, _ error: NSError?) -> Void)?) {
|
public func stopVideoRecording(completion:(videoURL: NSURL?, error: NSError?) -> Void) {
|
||||||
if let runningMovieOutput = movieOutput {
|
if let runningMovieOutput = movieOutput {
|
||||||
if runningMovieOutput.isRecording {
|
if runningMovieOutput.recording {
|
||||||
videoCompletion = completion
|
videoCompletion = completion
|
||||||
runningMovieOutput.stopRecording()
|
runningMovieOutput.stopRecording()
|
||||||
}
|
}
|
||||||
|
|
@ -407,96 +426,79 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Current camera status.
|
Current camera status.
|
||||||
|
|
||||||
:returns: Current state of the camera: Ready / AccessDenied / NoDeviceFound / NotDetermined
|
:returns: Current state of the camera: Ready / AccessDenied / NoDeviceFound / NotDetermined
|
||||||
*/
|
*/
|
||||||
open func currentCameraStatus() -> CameraState {
|
public func currentCameraStatus() -> CameraState {
|
||||||
return _checkIfCameraIsAvailable()
|
return _checkIfCameraIsAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Change current flash mode to next value from available ones.
|
Change current flash mode to next value from available ones.
|
||||||
|
|
||||||
:returns: Current flash mode: Off / On / Auto
|
:returns: Current flash mode: Off / On / Auto
|
||||||
*/
|
*/
|
||||||
open func changeFlashMode() -> CameraFlashMode {
|
public func changeFlashMode() -> CameraFlashMode {
|
||||||
flashMode = CameraFlashMode(rawValue: (flashMode.rawValue+1)%3)!
|
flashMode = CameraFlashMode(rawValue: (flashMode.rawValue+1)%3)!
|
||||||
return flashMode
|
return flashMode
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Change current output quality mode to next value from available ones.
|
Change current output quality mode to next value from available ones.
|
||||||
|
|
||||||
:returns: Current quality mode: Low / Medium / High
|
:returns: Current quality mode: Low / Medium / High
|
||||||
*/
|
*/
|
||||||
open func changeQualityMode() -> CameraOutputQuality {
|
public func changeQualityMode() -> CameraOutputQuality {
|
||||||
cameraOutputQuality = CameraOutputQuality(rawValue: (cameraOutputQuality.rawValue+1)%3)!
|
cameraOutputQuality = CameraOutputQuality(rawValue: (cameraOutputQuality.rawValue+1)%3)!
|
||||||
return cameraOutputQuality
|
return cameraOutputQuality
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - AVCaptureFileOutputRecordingDelegate
|
// MARK: - AVCaptureFileOutputRecordingDelegate
|
||||||
|
|
||||||
open func capture(_ captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAt fileURL: URL!, fromConnections connections: [Any]!) {
|
public func captureOutput(captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAtURL fileURL: NSURL!, fromConnections connections: [AnyObject]!) {
|
||||||
captureSession?.beginConfiguration()
|
captureSession?.beginConfiguration()
|
||||||
if flashMode != .off {
|
if flashMode != .Off {
|
||||||
_updateTorch(flashMode)
|
_updateTorch(flashMode)
|
||||||
}
|
}
|
||||||
captureSession?.commitConfiguration()
|
captureSession?.commitConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
open func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
|
public func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
|
||||||
_updateTorch(.off)
|
_updateTorch(.Off)
|
||||||
if (error != nil) {
|
if (error != nil) {
|
||||||
_show(NSLocalizedString("Unable to save video to the iPhone", comment:""), message: error.localizedDescription)
|
_show(NSLocalizedString("Unable to save video to the iPhone", comment:""), message: error.localizedDescription)
|
||||||
} else {
|
} else {
|
||||||
|
if let validLibrary = library {
|
||||||
if writeFilesToPhoneLibrary {
|
if writeFilesToPhoneLibrary {
|
||||||
|
validLibrary.writeVideoAtPathToSavedPhotosAlbum(outputFileURL, completionBlock: { (assetURL: NSURL?, error: NSError?) -> Void in
|
||||||
if PHPhotoLibrary.authorizationStatus() == .authorized {
|
if (error != nil) {
|
||||||
saveVideoToLibrary(outputFileURL)
|
self._show(NSLocalizedString("Unable to save video to the iPhone.", comment:""), message: error!.localizedDescription)
|
||||||
}
|
self._executeVideoCompletionWithURL(nil, error: error)
|
||||||
else {
|
} else {
|
||||||
PHPhotoLibrary.requestAuthorization({ (autorizationStatus) in
|
if let validAssetURL = assetURL {
|
||||||
if autorizationStatus == .authorized {
|
self._executeVideoCompletionWithURL(validAssetURL, error: error)
|
||||||
self.saveVideoToLibrary(outputFileURL)
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
_executeVideoCompletionWithURL(outputFileURL, error: error)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
_executeVideoCompletionWithURL(outputFileURL, error: error as NSError?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func saveVideoToLibrary(_ fileURL: URL) {
|
|
||||||
if let validLibrary = library {
|
|
||||||
validLibrary.performChanges({
|
|
||||||
|
|
||||||
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: fileURL)
|
|
||||||
}, completionHandler: { success, error in
|
|
||||||
if (error != nil) {
|
|
||||||
self._show(NSLocalizedString("Unable to save video to the iPhone.", comment:""), message: error!.localizedDescription)
|
|
||||||
self._executeVideoCompletionWithURL(nil, error: error as NSError?)
|
|
||||||
} else {
|
|
||||||
self._executeVideoCompletionWithURL(fileURL, error: error as NSError?)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - UIGestureRecognizerDelegate
|
// MARK: - UIGestureRecognizerDelegate
|
||||||
|
|
||||||
fileprivate func attachZoom(_ view: UIView) {
|
private func attachZoom(view: UIView) {
|
||||||
let pinch = UIPinchGestureRecognizer(target: self, action: #selector(CameraManager._zoomStart(_:)))
|
let pinch = UIPinchGestureRecognizer(target: self, action: #selector(CameraManager._zoomStart(_:)))
|
||||||
view.addGestureRecognizer(pinch)
|
view.addGestureRecognizer(pinch)
|
||||||
pinch.delegate = self
|
pinch.delegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
open func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
|
public func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||||
|
|
||||||
if gestureRecognizer.isKind(of: UIPinchGestureRecognizer.self) {
|
if gestureRecognizer.isKindOfClass(UIPinchGestureRecognizer) {
|
||||||
beginZoomScale = zoomScale;
|
beginZoomScale = zoomScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -504,18 +506,18 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
fileprivate func _zoomStart(_ recognizer: UIPinchGestureRecognizer) {
|
private func _zoomStart(recognizer: UIPinchGestureRecognizer) {
|
||||||
guard let view = embeddingView,
|
guard let view = embeddingView,
|
||||||
let previewLayer = previewLayer
|
previewLayer = previewLayer
|
||||||
else { return }
|
else { return }
|
||||||
|
|
||||||
var allTouchesOnPreviewLayer = true
|
var allTouchesOnPreviewLayer = true
|
||||||
let numTouch = recognizer.numberOfTouches
|
let numTouch = recognizer.numberOfTouches()
|
||||||
|
|
||||||
for i in 0 ..< numTouch {
|
for i in 0 ..< numTouch {
|
||||||
let location = recognizer.location(ofTouch: i, in: view)
|
let location = recognizer.locationOfTouch(i, inView: view)
|
||||||
let convertedTouch = previewLayer.convert(location, from: previewLayer.superlayer)
|
let convertedTouch = previewLayer.convertPoint(location, fromLayer: previewLayer.superlayer)
|
||||||
if !previewLayer.contains(convertedTouch) {
|
if !previewLayer.containsPoint(convertedTouch) {
|
||||||
allTouchesOnPreviewLayer = false
|
allTouchesOnPreviewLayer = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -525,7 +527,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _zoom(_ scale: CGFloat) {
|
private func _zoom(scale: CGFloat) {
|
||||||
do {
|
do {
|
||||||
let captureDevice = AVCaptureDevice.devices().first as? AVCaptureDevice
|
let captureDevice = AVCaptureDevice.devices().first as? AVCaptureDevice
|
||||||
try captureDevice?.lockForConfiguration()
|
try captureDevice?.lockForConfiguration()
|
||||||
|
|
@ -543,12 +545,12 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
|
|
||||||
// MARK: - CameraManager()
|
// MARK: - CameraManager()
|
||||||
|
|
||||||
fileprivate func _updateTorch(_ flashMode: CameraFlashMode) {
|
private func _updateTorch(flashMode: CameraFlashMode) {
|
||||||
captureSession?.beginConfiguration()
|
captureSession?.beginConfiguration()
|
||||||
let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo)
|
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
|
||||||
for device in devices! {
|
for device in devices {
|
||||||
let captureDevice = device as! AVCaptureDevice
|
let captureDevice = device as! AVCaptureDevice
|
||||||
if (captureDevice.position == AVCaptureDevicePosition.back) {
|
if (captureDevice.position == AVCaptureDevicePosition.Back) {
|
||||||
let avTorchMode = AVCaptureTorchMode(rawValue: flashMode.rawValue)
|
let avTorchMode = AVCaptureTorchMode(rawValue: flashMode.rawValue)
|
||||||
if (captureDevice.isTorchModeSupported(avTorchMode!)) {
|
if (captureDevice.isTorchModeSupported(avTorchMode!)) {
|
||||||
do {
|
do {
|
||||||
|
|
@ -565,18 +567,18 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fileprivate func _executeVideoCompletionWithURL(_ url: URL?, error: NSError?) {
|
private func _executeVideoCompletionWithURL(url: NSURL?, error: NSError?) {
|
||||||
if let validCompletion = videoCompletion {
|
if let validCompletion = videoCompletion {
|
||||||
validCompletion(url, error)
|
validCompletion(videoURL: url, error: error)
|
||||||
videoCompletion = nil
|
videoCompletion = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _getMovieOutput() -> AVCaptureMovieFileOutput {
|
private func _getMovieOutput() -> AVCaptureMovieFileOutput {
|
||||||
var shouldReinitializeMovieOutput = movieOutput == nil
|
var shouldReinitializeMovieOutput = movieOutput == nil
|
||||||
if !shouldReinitializeMovieOutput {
|
if !shouldReinitializeMovieOutput {
|
||||||
if let connection = movieOutput!.connection(withMediaType: AVMediaTypeVideo) {
|
if let connection = movieOutput!.connectionWithMediaType(AVMediaTypeVideo) {
|
||||||
shouldReinitializeMovieOutput = shouldReinitializeMovieOutput || !connection.isActive
|
shouldReinitializeMovieOutput = shouldReinitializeMovieOutput || !connection.active
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -595,11 +597,11 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
return movieOutput!
|
return movieOutput!
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _getStillImageOutput() -> AVCaptureStillImageOutput {
|
private func _getStillImageOutput() -> AVCaptureStillImageOutput {
|
||||||
var shouldReinitializeStillImageOutput = stillImageOutput == nil
|
var shouldReinitializeStillImageOutput = stillImageOutput == nil
|
||||||
if !shouldReinitializeStillImageOutput {
|
if !shouldReinitializeStillImageOutput {
|
||||||
if let connection = stillImageOutput!.connection(withMediaType: AVMediaTypeVideo) {
|
if let connection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) {
|
||||||
shouldReinitializeStillImageOutput = shouldReinitializeStillImageOutput || !connection.isActive
|
shouldReinitializeStillImageOutput = shouldReinitializeStillImageOutput || !connection.active
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if shouldReinitializeStillImageOutput {
|
if shouldReinitializeStillImageOutput {
|
||||||
|
|
@ -616,26 +618,26 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
return stillImageOutput!
|
return stillImageOutput!
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc fileprivate func _orientationChanged() {
|
@objc private func _orientationChanged() {
|
||||||
var currentConnection: AVCaptureConnection?;
|
var currentConnection: AVCaptureConnection?;
|
||||||
switch cameraOutputMode {
|
switch cameraOutputMode {
|
||||||
case .stillImage:
|
case .StillImage:
|
||||||
currentConnection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo)
|
currentConnection = stillImageOutput?.connectionWithMediaType(AVMediaTypeVideo)
|
||||||
case .videoOnly, .videoWithMic:
|
case .VideoOnly, .VideoWithMic:
|
||||||
currentConnection = _getMovieOutput().connection(withMediaType: AVMediaTypeVideo)
|
currentConnection = _getMovieOutput().connectionWithMediaType(AVMediaTypeVideo)
|
||||||
}
|
}
|
||||||
if let validPreviewLayer = previewLayer {
|
if let validPreviewLayer = previewLayer {
|
||||||
if let validPreviewLayerConnection = validPreviewLayer.connection {
|
if let validPreviewLayerConnection = validPreviewLayer.connection {
|
||||||
if validPreviewLayerConnection.isVideoOrientationSupported {
|
if validPreviewLayerConnection.supportsVideoOrientation {
|
||||||
validPreviewLayerConnection.videoOrientation = _currentVideoOrientation()
|
validPreviewLayerConnection.videoOrientation = _currentVideoOrientation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let validOutputLayerConnection = currentConnection {
|
if let validOutputLayerConnection = currentConnection {
|
||||||
if validOutputLayerConnection.isVideoOrientationSupported {
|
if validOutputLayerConnection.supportsVideoOrientation {
|
||||||
validOutputLayerConnection.videoOrientation = _currentVideoOrientation()
|
validOutputLayerConnection.videoOrientation = _currentVideoOrientation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DispatchQueue.main.async(execute: { () -> Void in
|
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||||
if let validEmbeddingView = self.embeddingView {
|
if let validEmbeddingView = self.embeddingView {
|
||||||
validPreviewLayer.frame = validEmbeddingView.bounds
|
validPreviewLayer.frame = validEmbeddingView.bounds
|
||||||
}
|
}
|
||||||
|
|
@ -643,26 +645,26 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _currentVideoOrientation() -> AVCaptureVideoOrientation {
|
private func _currentVideoOrientation() -> AVCaptureVideoOrientation {
|
||||||
switch UIDevice.current.orientation {
|
switch UIDevice.currentDevice().orientation {
|
||||||
case .landscapeLeft:
|
case .LandscapeLeft:
|
||||||
return .landscapeRight
|
return .LandscapeRight
|
||||||
case .landscapeRight:
|
case .LandscapeRight:
|
||||||
return .landscapeLeft
|
return .LandscapeLeft
|
||||||
default:
|
default:
|
||||||
return .portrait
|
return .Portrait
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _canLoadCamera() -> Bool {
|
private func _canLoadCamera() -> Bool {
|
||||||
let currentCameraState = _checkIfCameraIsAvailable()
|
let currentCameraState = _checkIfCameraIsAvailable()
|
||||||
return currentCameraState == .ready || (currentCameraState == .notDetermined && showAccessPermissionPopupAutomatically)
|
return currentCameraState == .Ready || (currentCameraState == .NotDetermined && showAccessPermissionPopupAutomatically)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _setupCamera(_ completion: @escaping (Void) -> Void) {
|
private func _setupCamera(completion: Void -> Void) {
|
||||||
captureSession = AVCaptureSession()
|
captureSession = AVCaptureSession()
|
||||||
|
|
||||||
sessionQueue.async(execute: {
|
dispatch_async(sessionQueue, {
|
||||||
if let validCaptureSession = self.captureSession {
|
if let validCaptureSession = self.captureSession {
|
||||||
validCaptureSession.beginConfiguration()
|
validCaptureSession.beginConfiguration()
|
||||||
validCaptureSession.sessionPreset = AVCaptureSessionPresetHigh
|
validCaptureSession.sessionPreset = AVCaptureSessionPresetHigh
|
||||||
|
|
@ -683,24 +685,24 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _startFollowingDeviceOrientation() {
|
private func _startFollowingDeviceOrientation() {
|
||||||
if shouldRespondToOrientationChanges && !cameraIsObservingDeviceOrientation {
|
if shouldRespondToOrientationChanges && !cameraIsObservingDeviceOrientation {
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(CameraManager._orientationChanged), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
|
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(CameraManager._orientationChanged), name: UIDeviceOrientationDidChangeNotification, object: nil)
|
||||||
cameraIsObservingDeviceOrientation = true
|
cameraIsObservingDeviceOrientation = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _stopFollowingDeviceOrientation() {
|
private func _stopFollowingDeviceOrientation() {
|
||||||
if cameraIsObservingDeviceOrientation {
|
if cameraIsObservingDeviceOrientation {
|
||||||
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
|
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIDeviceOrientationDidChangeNotification, object: nil)
|
||||||
cameraIsObservingDeviceOrientation = false
|
cameraIsObservingDeviceOrientation = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _addPreviewLayerToView(_ view: UIView) {
|
private func _addPreviewLayerToView(view: UIView) {
|
||||||
embeddingView = view
|
embeddingView = view
|
||||||
attachZoom(view)
|
attachZoom(view)
|
||||||
DispatchQueue.main.async(execute: { () -> Void in
|
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||||
guard let _ = self.previewLayer else {
|
guard let _ = self.previewLayer else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -710,54 +712,54 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _setupMaxZoomScale() {
|
private func _setupMaxZoomScale() {
|
||||||
var maxZoom = CGFloat(1.0)
|
var maxZoom = CGFloat(1.0)
|
||||||
beginZoomScale = CGFloat(1.0)
|
beginZoomScale = CGFloat(1.0)
|
||||||
|
|
||||||
if cameraDevice == .back {
|
if cameraDevice == .Back {
|
||||||
maxZoom = (backCameraDevice?.activeFormat.videoMaxZoomFactor)!
|
maxZoom = (backCameraDevice?.activeFormat.videoMaxZoomFactor)!
|
||||||
}
|
}
|
||||||
else if cameraDevice == .front {
|
else if cameraDevice == .Front {
|
||||||
maxZoom = (frontCameraDevice?.activeFormat.videoMaxZoomFactor)!
|
maxZoom = (frontCameraDevice?.activeFormat.videoMaxZoomFactor)!
|
||||||
}
|
}
|
||||||
|
|
||||||
maxZoomScale = maxZoom
|
maxZoomScale = maxZoom
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _checkIfCameraIsAvailable() -> CameraState {
|
private func _checkIfCameraIsAvailable() -> CameraState {
|
||||||
let deviceHasCamera = UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.rear) || UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.front)
|
let deviceHasCamera = UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Rear) || UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front)
|
||||||
if deviceHasCamera {
|
if deviceHasCamera {
|
||||||
let authorizationStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
|
let authorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
|
||||||
let userAgreedToUseIt = authorizationStatus == .authorized
|
let userAgreedToUseIt = authorizationStatus == .Authorized
|
||||||
if userAgreedToUseIt {
|
if userAgreedToUseIt {
|
||||||
return .ready
|
return .Ready
|
||||||
} else if authorizationStatus == AVAuthorizationStatus.notDetermined {
|
} else if authorizationStatus == AVAuthorizationStatus.NotDetermined {
|
||||||
return .notDetermined
|
return .NotDetermined
|
||||||
} else {
|
} else {
|
||||||
_show(NSLocalizedString("Camera access denied", comment:""), message:NSLocalizedString("You need to go to settings app and grant acces to the camera device to use it.", comment:""))
|
_show(NSLocalizedString("Camera access denied", comment:""), message:NSLocalizedString("You need to go to settings app and grant acces to the camera device to use it.", comment:""))
|
||||||
return .accessDenied
|
return .AccessDenied
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_show(NSLocalizedString("Camera unavailable", comment:""), message:NSLocalizedString("The device does not have a camera.", comment:""))
|
_show(NSLocalizedString("Camera unavailable", comment:""), message:NSLocalizedString("The device does not have a camera.", comment:""))
|
||||||
return .noDeviceFound
|
return .NoDeviceFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _setupOutputMode(_ newCameraOutputMode: CameraOutputMode, oldCameraOutputMode: CameraOutputMode?) {
|
private func _setupOutputMode(newCameraOutputMode: CameraOutputMode, oldCameraOutputMode: CameraOutputMode?) {
|
||||||
captureSession?.beginConfiguration()
|
captureSession?.beginConfiguration()
|
||||||
|
|
||||||
if let cameraOutputToRemove = oldCameraOutputMode {
|
if let cameraOutputToRemove = oldCameraOutputMode {
|
||||||
// remove current setting
|
// remove current setting
|
||||||
switch cameraOutputToRemove {
|
switch cameraOutputToRemove {
|
||||||
case .stillImage:
|
case .StillImage:
|
||||||
if let validStillImageOutput = stillImageOutput {
|
if let validStillImageOutput = stillImageOutput {
|
||||||
captureSession?.removeOutput(validStillImageOutput)
|
captureSession?.removeOutput(validStillImageOutput)
|
||||||
}
|
}
|
||||||
case .videoOnly, .videoWithMic:
|
case .VideoOnly, .VideoWithMic:
|
||||||
if let validMovieOutput = movieOutput {
|
if let validMovieOutput = movieOutput {
|
||||||
captureSession?.removeOutput(validMovieOutput)
|
captureSession?.removeOutput(validMovieOutput)
|
||||||
}
|
}
|
||||||
if cameraOutputToRemove == .videoWithMic {
|
if cameraOutputToRemove == .VideoWithMic {
|
||||||
_removeMicInput()
|
_removeMicInput()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -765,7 +767,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
|
|
||||||
// configure new devices
|
// configure new devices
|
||||||
switch newCameraOutputMode {
|
switch newCameraOutputMode {
|
||||||
case .stillImage:
|
case .StillImage:
|
||||||
if (stillImageOutput == nil) {
|
if (stillImageOutput == nil) {
|
||||||
_setupOutputs()
|
_setupOutputs()
|
||||||
}
|
}
|
||||||
|
|
@ -776,10 +778,10 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .videoOnly, .videoWithMic:
|
case .VideoOnly, .VideoWithMic:
|
||||||
captureSession?.addOutput(_getMovieOutput())
|
captureSession?.addOutput(_getMovieOutput())
|
||||||
|
|
||||||
if newCameraOutputMode == .videoWithMic {
|
if newCameraOutputMode == .VideoWithMic {
|
||||||
if let validMic = _deviceInputFromDevice(mic) {
|
if let validMic = _deviceInputFromDevice(mic) {
|
||||||
captureSession?.addInput(validMic)
|
captureSession?.addInput(validMic)
|
||||||
}
|
}
|
||||||
|
|
@ -790,7 +792,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
_orientationChanged()
|
_orientationChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _setupOutputs() {
|
private func _setupOutputs() {
|
||||||
if (stillImageOutput == nil) {
|
if (stillImageOutput == nil) {
|
||||||
stillImageOutput = AVCaptureStillImageOutput()
|
stillImageOutput = AVCaptureStillImageOutput()
|
||||||
}
|
}
|
||||||
|
|
@ -799,35 +801,35 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
movieOutput!.movieFragmentInterval = kCMTimeInvalid
|
movieOutput!.movieFragmentInterval = kCMTimeInvalid
|
||||||
}
|
}
|
||||||
if library == nil {
|
if library == nil {
|
||||||
library = PHPhotoLibrary.shared()
|
library = ALAssetsLibrary()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _setupPreviewLayer() {
|
private func _setupPreviewLayer() {
|
||||||
if let validCaptureSession = captureSession {
|
if let validCaptureSession = captureSession {
|
||||||
previewLayer = AVCaptureVideoPreviewLayer(session: validCaptureSession)
|
previewLayer = AVCaptureVideoPreviewLayer(session: validCaptureSession)
|
||||||
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
|
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _updateCameraDevice(_ deviceType: CameraDevice) {
|
private func _updateCameraDevice(deviceType: CameraDevice) {
|
||||||
if let validCaptureSession = captureSession {
|
if let validCaptureSession = captureSession {
|
||||||
validCaptureSession.beginConfiguration()
|
validCaptureSession.beginConfiguration()
|
||||||
let inputs = validCaptureSession.inputs as! [AVCaptureInput]
|
let inputs = validCaptureSession.inputs as! [AVCaptureInput]
|
||||||
|
|
||||||
for input in inputs {
|
for input in inputs {
|
||||||
if let deviceInput = input as? AVCaptureDeviceInput {
|
if let deviceInput = input as? AVCaptureDeviceInput {
|
||||||
if deviceInput.device == backCameraDevice && cameraDevice == .front {
|
if deviceInput.device == backCameraDevice && cameraDevice == .Front {
|
||||||
validCaptureSession.removeInput(deviceInput)
|
validCaptureSession.removeInput(deviceInput)
|
||||||
break;
|
break;
|
||||||
} else if deviceInput.device == frontCameraDevice && cameraDevice == .back {
|
} else if deviceInput.device == frontCameraDevice && cameraDevice == .Back {
|
||||||
validCaptureSession.removeInput(deviceInput)
|
validCaptureSession.removeInput(deviceInput)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch cameraDevice {
|
switch cameraDevice {
|
||||||
case .front:
|
case .Front:
|
||||||
if hasFrontCamera {
|
if hasFrontCamera {
|
||||||
if let validFrontDevice = _deviceInputFromDevice(frontCameraDevice) {
|
if let validFrontDevice = _deviceInputFromDevice(frontCameraDevice) {
|
||||||
if !inputs.contains(validFrontDevice) {
|
if !inputs.contains(validFrontDevice) {
|
||||||
|
|
@ -835,7 +837,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .back:
|
case .Back:
|
||||||
if let validBackDevice = _deviceInputFromDevice(backCameraDevice) {
|
if let validBackDevice = _deviceInputFromDevice(backCameraDevice) {
|
||||||
if !inputs.contains(validBackDevice) {
|
if !inputs.contains(validBackDevice) {
|
||||||
validCaptureSession.addInput(validBackDevice)
|
validCaptureSession.addInput(validBackDevice)
|
||||||
|
|
@ -846,12 +848,12 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _updateFlasMode(_ flashMode: CameraFlashMode) {
|
private func _updateFlasMode(flashMode: CameraFlashMode) {
|
||||||
captureSession?.beginConfiguration()
|
captureSession?.beginConfiguration()
|
||||||
let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo)
|
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
|
||||||
for device in devices! {
|
for device in devices {
|
||||||
let captureDevice = device as! AVCaptureDevice
|
let captureDevice = device as! AVCaptureDevice
|
||||||
if (captureDevice.position == AVCaptureDevicePosition.back) {
|
if (captureDevice.position == AVCaptureDevicePosition.Back) {
|
||||||
let avFlashMode = AVCaptureFlashMode(rawValue: flashMode.rawValue)
|
let avFlashMode = AVCaptureFlashMode(rawValue: flashMode.rawValue)
|
||||||
if (captureDevice.isFlashModeSupported(avFlashMode!)) {
|
if (captureDevice.isFlashModeSupported(avFlashMode!)) {
|
||||||
do {
|
do {
|
||||||
|
|
@ -867,16 +869,16 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
captureSession?.commitConfiguration()
|
captureSession?.commitConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _updateCameraQualityMode(_ newCameraOutputQuality: CameraOutputQuality) {
|
private func _updateCameraQualityMode(newCameraOutputQuality: CameraOutputQuality) {
|
||||||
if let validCaptureSession = captureSession {
|
if let validCaptureSession = captureSession {
|
||||||
var sessionPreset = AVCaptureSessionPresetLow
|
var sessionPreset = AVCaptureSessionPresetLow
|
||||||
switch (newCameraOutputQuality) {
|
switch (newCameraOutputQuality) {
|
||||||
case CameraOutputQuality.low:
|
case CameraOutputQuality.Low:
|
||||||
sessionPreset = AVCaptureSessionPresetLow
|
sessionPreset = AVCaptureSessionPresetLow
|
||||||
case CameraOutputQuality.medium:
|
case CameraOutputQuality.Medium:
|
||||||
sessionPreset = AVCaptureSessionPresetMedium
|
sessionPreset = AVCaptureSessionPresetMedium
|
||||||
case CameraOutputQuality.high:
|
case CameraOutputQuality.High:
|
||||||
if cameraOutputMode == .stillImage {
|
if cameraOutputMode == .StillImage {
|
||||||
sessionPreset = AVCaptureSessionPresetPhoto
|
sessionPreset = AVCaptureSessionPresetPhoto
|
||||||
} else {
|
} else {
|
||||||
sessionPreset = AVCaptureSessionPresetHigh
|
sessionPreset = AVCaptureSessionPresetHigh
|
||||||
|
|
@ -894,7 +896,7 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _removeMicInput() {
|
private func _removeMicInput() {
|
||||||
guard let inputs = captureSession?.inputs as? [AVCaptureInput] else { return }
|
guard let inputs = captureSession?.inputs as? [AVCaptureInput] else { return }
|
||||||
|
|
||||||
for input in inputs {
|
for input in inputs {
|
||||||
|
|
@ -907,15 +909,15 @@ open class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate, UIGest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _show(_ title: String, message: String) {
|
private func _show(title: String, message: String) {
|
||||||
if showErrorsToUsers {
|
if showErrorsToUsers {
|
||||||
DispatchQueue.main.async(execute: { () -> Void in
|
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||||
self.showErrorBlock(title, message)
|
self.showErrorBlock(erTitle: title, erMessage: message)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func _deviceInputFromDevice(_ device: AVCaptureDevice?) -> AVCaptureDeviceInput? {
|
private func _deviceInputFromDevice(device: AVCaptureDevice?) -> AVCaptureDeviceInput? {
|
||||||
guard let validDevice = device else { return nil }
|
guard let validDevice = device else { return nil }
|
||||||
do {
|
do {
|
||||||
return try AVCaptureDeviceInput(device: validDevice)
|
return try AVCaptureDeviceInput(device: validDevice)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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,42 +66,42 @@ 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.capturePictureWithCompletion({ (image, 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)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let vc: ImageViewController? = self.storyboard?.instantiateViewController(withIdentifier: "ImageVC") as? ImageViewController
|
let vc: ImageViewController? = self.storyboard?.instantiateViewControllerWithIdentifier("ImageVC") as? ImageViewController
|
||||||
if let validVC: ImageViewController = vc {
|
if let validVC: ImageViewController = vc {
|
||||||
if let capturedImage = image {
|
if let capturedImage = image {
|
||||||
validVC.image = capturedImage
|
validVC.image = capturedImage
|
||||||
|
|
@ -110,51 +110,51 @@ class ViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
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.stopVideoRecording({ (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.askUserForCameraPermission({ 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 +163,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue