Merge branch 'lexrus-master'

This commit is contained in:
Natalia Terlecka 2015-05-12 09:39:33 +01:00
commit 7b16276fbb
9 changed files with 358 additions and 66 deletions

View File

@ -0,0 +1,19 @@
//
// CameraManager.h
// CameraManager
//
// Created by Lex Tang on 4/9/15.
// Copyright (c) 2015 imaginaryCloud. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for CameraManager.
FOUNDATION_EXPORT double CameraManagerVersionNumber;
//! Project version string for CameraManager.
FOUNDATION_EXPORT const unsigned char CameraManagerVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <CameraManager/PublicHeader.h>

26
CameraManager/Info.plist Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@ -1,18 +1,16 @@
####Camera Manager
# Camera Manager
[![CocoaPods](https://img.shields.io/cocoapods/v/CameraManager.svg)](https://github.com/imaginary-cloud/CameraManager) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
V1.0.12 (23-Mar-2015)
####About
This is a simple swift class to provide all the configurations you need to create custom camera view in your app.
This is a simple Swift class to provide all the configurations you need to create custom camera view in your app.
It follows orientation change and updates UI accordingly, supports front and rear camera selection, different flash modes, inputs and outputs.
Just drag, drop and use.
####Installation with CocoaPods
## Installation with CocoaPods
The easiest way to install the CameraManager is with: [CocoaPods](http://cocoapods.org)
## Podfile
### Podfile
```ruby
use_frameworks!
@ -20,7 +18,18 @@ use_frameworks!
pod 'CameraManager', '~> 1.0'
```
####How to use
## Installation with Carthage
[Carthage](https://github.com/Carthage/Carthage) is another dependency management tool written in Swift.
Add the following line to your Cartfile:
```
github "imaginary-cloud/CameraManager" >= 1.0
```
And run `carthage update` to build the dynamic framework.
## How to use
To use it you just add the preview layer to your desired view, you'll get back the state of the camera if it's unavailable, ready or the user denied assess to it.
```swift
CameraManager.sharedInstance.addPreeviewLayerToView(self.cameraView)
@ -95,10 +104,10 @@ CameraManager.sharedInstance.stopRecordingVideo({ (videoURL, error) -> Void in
})
```
####Support
## Support
Supports iOS 8 and above
Supports iOS 8 and above. Xcode 6.3 is required to build the latest code written in Swift 1.2.
####License
## License
Copyright © 2014 ImaginaryCloud, imaginarycloud.com. This library is licensed under the MIT license.
Copyright © 2015 ImaginaryCloud, imaginarycloud.com. This library is licensed under the MIT license.

View File

@ -14,8 +14,36 @@
454C1F5119E82E2500C81915 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 454C1F4F19E82E2500C81915 /* LaunchScreen.xib */; };
454C1F6719E8316A00C81915 /* CameraManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454C1F6619E8316A00C81915 /* CameraManager.swift */; };
45A23C181A656BDC00FB48F3 /* ImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45A23C171A656BDC00FB48F3 /* ImageViewController.swift */; };
D71DE8861AD677A7001E62F1 /* CameraManager.h in Headers */ = {isa = PBXBuildFile; fileRef = D71DE8851AD677A7001E62F1 /* CameraManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
D71DE8981AD677A8001E62F1 /* CameraManager.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D71DE8811AD677A7001E62F1 /* CameraManager.framework */; };
D71DE8991AD677A8001E62F1 /* CameraManager.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D71DE8811AD677A7001E62F1 /* CameraManager.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
D71DE8A11AD677EF001E62F1 /* CameraManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454C1F6619E8316A00C81915 /* CameraManager.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
D71DE8961AD677A8001E62F1 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 454C1F3919E82E2500C81915 /* Project object */;
proxyType = 1;
remoteGlobalIDString = D71DE8801AD677A7001E62F1;
remoteInfo = CameraManager;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
D71DE89D1AD677A8001E62F1 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
D71DE8991AD677A8001E62F1 /* CameraManager.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
454C1F4119E82E2500C81915 /* camera.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = camera.app; sourceTree = BUILT_PRODUCTS_DIR; };
454C1F4519E82E2500C81915 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -26,10 +54,21 @@
454C1F5019E82E2500C81915 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
454C1F6619E8316A00C81915 /* CameraManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraManager.swift; sourceTree = "<group>"; };
45A23C171A656BDC00FB48F3 /* ImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageViewController.swift; sourceTree = "<group>"; };
D71DE8811AD677A7001E62F1 /* CameraManager.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CameraManager.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D71DE8841AD677A7001E62F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D71DE8851AD677A7001E62F1 /* CameraManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CameraManager.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
454C1F3E19E82E2500C81915 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D71DE8981AD677A8001E62F1 /* CameraManager.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D71DE87D1AD677A7001E62F1 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
@ -43,6 +82,7 @@
isa = PBXGroup;
children = (
454C1F4319E82E2500C81915 /* camera */,
D71DE8821AD677A7001E62F1 /* CameraManager */,
454C1F4219E82E2500C81915 /* Products */,
);
sourceTree = "<group>";
@ -51,6 +91,7 @@
isa = PBXGroup;
children = (
454C1F4119E82E2500C81915 /* camera.app */,
D71DE8811AD677A7001E62F1 /* CameraManager.framework */,
);
name = Products;
sourceTree = "<group>";
@ -86,8 +127,36 @@
name = "Example app view controllers";
sourceTree = "<group>";
};
D71DE8821AD677A7001E62F1 /* CameraManager */ = {
isa = PBXGroup;
children = (
D71DE8851AD677A7001E62F1 /* CameraManager.h */,
D71DE8831AD677A7001E62F1 /* Supporting Files */,
);
path = CameraManager;
sourceTree = "<group>";
};
D71DE8831AD677A7001E62F1 /* Supporting Files */ = {
isa = PBXGroup;
children = (
D71DE8841AD677A7001E62F1 /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
D71DE87E1AD677A7001E62F1 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
D71DE8861AD677A7001E62F1 /* CameraManager.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
454C1F4019E82E2500C81915 /* camera */ = {
isa = PBXNativeTarget;
@ -96,16 +165,36 @@
454C1F3D19E82E2500C81915 /* Sources */,
454C1F3E19E82E2500C81915 /* Frameworks */,
454C1F3F19E82E2500C81915 /* Resources */,
D71DE89D1AD677A8001E62F1 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
D71DE8971AD677A8001E62F1 /* PBXTargetDependency */,
);
name = camera;
productName = camera;
productReference = 454C1F4119E82E2500C81915 /* camera.app */;
productType = "com.apple.product-type.application";
};
D71DE8801AD677A7001E62F1 /* CameraManager */ = {
isa = PBXNativeTarget;
buildConfigurationList = D71DE89A1AD677A8001E62F1 /* Build configuration list for PBXNativeTarget "CameraManager" */;
buildPhases = (
D71DE87C1AD677A7001E62F1 /* Sources */,
D71DE87D1AD677A7001E62F1 /* Frameworks */,
D71DE87E1AD677A7001E62F1 /* Headers */,
D71DE87F1AD677A7001E62F1 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = CameraManager;
productName = CameraManager;
productReference = D71DE8811AD677A7001E62F1 /* CameraManager.framework */;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
@ -118,6 +207,9 @@
454C1F4019E82E2500C81915 = {
CreatedOnToolsVersion = 6.0.1;
};
D71DE8801AD677A7001E62F1 = {
CreatedOnToolsVersion = 6.3;
};
};
};
buildConfigurationList = 454C1F3C19E82E2500C81915 /* Build configuration list for PBXProject "camera" */;
@ -134,6 +226,7 @@
projectRoot = "";
targets = (
454C1F4019E82E2500C81915 /* camera */,
D71DE8801AD677A7001E62F1 /* CameraManager */,
);
};
/* End PBXProject section */
@ -149,6 +242,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
D71DE87F1AD677A7001E62F1 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
@ -163,8 +263,24 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
D71DE87C1AD677A7001E62F1 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D71DE8A11AD677EF001E62F1 /* CameraManager.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
D71DE8971AD677A8001E62F1 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = D71DE8801AD677A7001E62F1 /* CameraManager */;
targetProxy = D71DE8961AD677A8001E62F1 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
454C1F4A19E82E2500C81915 /* Main.storyboard */ = {
isa = PBXVariantGroup;
@ -203,8 +319,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "";
CODE_SIGN_IDENTITY = "iPhone Developer: Natalia Terlecki (8B96NL57N3)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Natalia Terlecki (8B96NL57N3)";
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
@ -224,7 +339,6 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
PROVISIONING_PROFILE = "c0db150a-581c-4aa9-bfc3-848f4eec3d08";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2";
@ -248,8 +362,7 @@
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Distribution: IndexSquare LDA (QM7HJTY23M)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: IndexSquare LDA (QM7HJTY23M)";
CODE_SIGN_IDENTITY = "iPhone Distribution";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
@ -262,7 +375,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
PROVISIONING_PROFILE = "3765a270-85d2-474b-9784-b02ccb687465";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
@ -273,13 +385,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer: Natalia Terlecki (8B96NL57N3)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Natalia Terlecki (8B96NL57N3)";
INFOPLIST_FILE = camera/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "c0db150a-581c-4aa9-bfc3-848f4eec3d08";
};
name = Debug;
};
@ -287,13 +396,57 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Distribution: IndexSquare LDA (QM7HJTY23M)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: IndexSquare LDA (QM7HJTY23M)";
INFOPLIST_FILE = camera/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "3765a270-85d2-474b-9784-b02ccb687465";
};
name = Release;
};
D71DE89B1AD677A8001E62F1 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = CameraManager/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Debug;
};
D71DE89C1AD677A8001E62F1 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_NO_COMMON_BLOCKS = YES;
INFOPLIST_FILE = CameraManager/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Release;
};
@ -318,6 +471,14 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
D71DE89A1AD677A8001E62F1 /* Build configuration list for PBXNativeTarget "CameraManager" */ = {
isa = XCConfigurationList;
buildConfigurations = (
D71DE89B1AD677A8001E62F1 /* Debug */,
D71DE89C1AD677A8001E62F1 /* Release */,
);
defaultConfigurationIsVisible = 0;
};
/* End XCConfigurationList section */
};
rootObject = 454C1F3919E82E2500C81915 /* Project object */;

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D71DE8801AD677A7001E62F1"
BuildableName = "CameraManager.framework"
BlueprintName = "CameraManager"
ReferencedContainer = "container:camera.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D71DE8801AD677A7001E62F1"
BuildableName = "CameraManager.framework"
BlueprintName = "CameraManager"
ReferencedContainer = "container:camera.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D71DE8801AD677A7001E62F1"
BuildableName = "CameraManager.framework"
BlueprintName = "CameraManager"
ReferencedContainer = "container:camera.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -63,7 +63,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
public var hasFrontCamera: Bool = {
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
for device in devices {
let captureDevice = device as AVCaptureDevice
let captureDevice = device as! AVCaptureDevice
if (captureDevice.position == .Front) {
return true
}
@ -75,7 +75,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
public var hasFlash: Bool = {
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
for device in devices {
let captureDevice = device as AVCaptureDevice
let captureDevice = device as! AVCaptureDevice
if (captureDevice.position == .Back) {
return captureDevice.hasFlash
}
@ -91,29 +91,29 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
set(newCameraDevice) {
if let validCaptureSession = self.captureSession {
validCaptureSession.beginConfiguration()
let inputs = validCaptureSession.inputs as [AVCaptureInput]
let inputs = validCaptureSession.inputs as! [AVCaptureInput]
switch newCameraDevice {
case .Front:
if self.hasFrontCamera {
if let validBackDevice = self.rearCamera? {
if let validBackDevice = self.rearCamera {
if contains(inputs, validBackDevice) {
validCaptureSession.removeInput(validBackDevice)
}
}
if let validFrontDevice = self.frontCamera? {
if let validFrontDevice = self.frontCamera {
if !contains(inputs, validFrontDevice) {
validCaptureSession.addInput(validFrontDevice)
}
}
}
case .Back:
if let validFrontDevice = self.frontCamera? {
if let validFrontDevice = self.frontCamera {
if contains(inputs, validFrontDevice) {
validCaptureSession.removeInput(validFrontDevice)
}
}
if let validBackDevice = self.rearCamera? {
if let validBackDevice = self.rearCamera {
if !contains(inputs, validBackDevice) {
validCaptureSession.addInput(validBackDevice)
}
@ -212,8 +212,8 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
public func addPreviewLayerToView(view: UIView, newCameraOutputMode: CameraOutputMode) -> CameraState
{
if self._canLoadCamera() {
if let validEmbedingView = self.embedingView? {
if let validPreviewLayer = self.previewLayer? {
if let validEmbedingView = self.embedingView {
if let validPreviewLayer = self.previewLayer {
validPreviewLayer.removeFromSuperlayer()
}
}
@ -268,7 +268,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
*/
public func resumeCaptureSession()
{
if let validCaptureSession = self.captureSession? {
if let validCaptureSession = self.captureSession {
if !validCaptureSession.running && self.cameraIsSetup {
validCaptureSession.startRunning()
self._startFollowingDeviceOrientation()
@ -279,7 +279,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
self.stopAndRemoveCaptureSession()
}
self._setupCamera({Void -> Void in
if let validEmbedingView = self.embedingView? {
if let validEmbedingView = self.embedingView {
self._addPreeviewLayerToView(validEmbedingView)
}
self._startFollowingDeviceOrientation()
@ -316,7 +316,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
if self.cameraOutputMode == .StillImage {
dispatch_async(self.sessionQueue, {
self._getStillImageOutput().captureStillImageAsynchronouslyFromConnection(self._getStillImageOutput().connectionWithMediaType(AVMediaTypeVideo), completionHandler: { [weak self] (sample: CMSampleBuffer!, error: NSError!) -> Void in
if (error? != nil) {
if (error != nil) {
dispatch_async(dispatch_get_main_queue(), {
if let weakSelf = self {
weakSelf._show(NSLocalizedString("Error", comment:""), message: error.localizedDescription)
@ -327,10 +327,10 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sample)
if let weakSelf = self {
if weakSelf.writeFilesToPhoneLibrary {
if let validLibrary = weakSelf.library? {
if let validLibrary = weakSelf.library {
validLibrary.writeImageDataToSavedPhotosAlbum(imageData, metadata:nil, completionBlock: {
(picUrl, error) -> Void in
if (error? != nil) {
if (error != nil) {
dispatch_async(dispatch_get_main_queue(), {
weakSelf._show(NSLocalizedString("Error", comment:""), message: error.localizedDescription)
})
@ -425,7 +425,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
if (error != nil) {
self._show(NSLocalizedString("Unable to save video to the iPhone", comment:""), message: error.localizedDescription)
} else {
if let validLibrary = self.library? {
if let validLibrary = self.library {
if self.writeFilesToPhoneLibrary {
validLibrary.writeVideoAtPathToSavedPhotosAlbum(outputFileURL, completionBlock: { (assetURL: NSURL?, error: NSError?) -> Void in
if (error != nil) {
@ -450,7 +450,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
self.captureSession?.beginConfiguration()
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
for device in devices {
let captureDevice = device as AVCaptureDevice
let captureDevice = device as! AVCaptureDevice
if (captureDevice.position == AVCaptureDevicePosition.Back) {
let avTorchMode = AVCaptureTorchMode(rawValue: flashMode.rawValue)
if (captureDevice.isTorchModeSupported(avTorchMode!)) {
@ -517,19 +517,19 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
case .VideoOnly, .VideoWithMic:
currentConnection = self._getMovieOutput().connectionWithMediaType(AVMediaTypeVideo)
}
if let validPreviewLayer = self.previewLayer? {
if let validPreviewLayerConnection = validPreviewLayer.connection? {
if let validPreviewLayer = self.previewLayer {
if let validPreviewLayerConnection = validPreviewLayer.connection {
if validPreviewLayerConnection.supportsVideoOrientation {
validPreviewLayerConnection.videoOrientation = self._currentVideoOrientation()
}
}
if let validOutputLayerConnection = currentConnection? {
if let validOutputLayerConnection = currentConnection {
if validOutputLayerConnection.supportsVideoOrientation {
validOutputLayerConnection.videoOrientation = self._currentVideoOrientation()
}
}
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if let validEmbedingView = self.embedingView? {
if let validEmbedingView = self.embedingView {
validPreviewLayer.frame = validEmbedingView.bounds
}
})
@ -559,7 +559,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
self.captureSession = AVCaptureSession()
dispatch_async(sessionQueue, {
if let validCaptureSession = self.captureSession? {
if let validCaptureSession = self.captureSession {
validCaptureSession.beginConfiguration()
validCaptureSession.sessionPreset = AVCaptureSessionPresetHigh
self._addVideoInput()
@ -630,7 +630,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
{
var error: NSError?
if (self.frontCamera? == nil) || (self.rearCamera? == nil) {
if (self.frontCamera == nil) || (self.rearCamera == nil) {
var videoFrontDevice: AVCaptureDevice?
var videoBackDevice: AVCaptureDevice?
for device: AnyObject in AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) {
@ -640,17 +640,17 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
videoFrontDevice = device as? AVCaptureDevice
}
}
if (self.frontCamera? == nil) {
if let validVideoFrontDevice = videoFrontDevice? {
self.frontCamera = AVCaptureDeviceInput.deviceInputWithDevice(validVideoFrontDevice, error: &error) as AVCaptureDeviceInput
if (self.frontCamera == nil) {
if let validVideoFrontDevice = videoFrontDevice {
self.frontCamera = AVCaptureDeviceInput.deviceInputWithDevice(validVideoFrontDevice, error: &error) as! AVCaptureDeviceInput
}
}
if (self.rearCamera? == nil) {
if let validVideoBackDevice = videoBackDevice? {
self.rearCamera = AVCaptureDeviceInput.deviceInputWithDevice(validVideoBackDevice, error: &error) as AVCaptureDeviceInput
if (self.rearCamera == nil) {
if let validVideoBackDevice = videoBackDevice {
self.rearCamera = AVCaptureDeviceInput.deviceInputWithDevice(validVideoBackDevice, error: &error) as! AVCaptureDeviceInput
}
}
if let validError = error? {
if let validError = error {
self._show(NSLocalizedString("Device setup error occured", comment:""), message: validError.localizedDescription)
}
}
@ -663,7 +663,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
var error: NSError?
let micDevice:AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio);
self.mic = AVCaptureDeviceInput.deviceInputWithDevice(micDevice, error: &error) as? AVCaptureDeviceInput;
if let errorHappened = error? {
if let errorHappened = error {
self.mic = nil
self._show(NSLocalizedString("Mic error", comment:""), message: errorHappened.description)
}
@ -678,15 +678,15 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
// remove current setting
switch _cameraOutputMode {
case .StillImage:
if let validStillImageOutput = self.stillImageOutput? {
if let validStillImageOutput = self.stillImageOutput {
self.captureSession?.removeOutput(validStillImageOutput)
}
case .VideoOnly, .VideoWithMic:
if let validMovieOutput = self.movieOutput? {
if let validMovieOutput = self.movieOutput {
self.captureSession?.removeOutput(validMovieOutput)
}
if _cameraOutputMode == .VideoWithMic {
if let validMic = self.mic? {
if let validMic = self.mic {
self.captureSession?.removeInput(validMic)
}
}
@ -699,7 +699,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
if (self.stillImageOutput == nil) {
self._setupOutputs()
}
if let validStillImageOutput = self.stillImageOutput? {
if let validStillImageOutput = self.stillImageOutput {
self.captureSession?.addOutput(validStillImageOutput)
}
case .VideoOnly, .VideoWithMic:
@ -709,7 +709,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
if (self.mic == nil) {
self._setupMic()
}
if let validMic = self.mic? {
if let validMic = self.mic {
self.captureSession?.addInput(validMic)
}
}
@ -735,7 +735,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
private func _setupPreviewLayer()
{
if let validCaptureSession = self.captureSession? {
if let validCaptureSession = self.captureSession {
self.previewLayer = AVCaptureVideoPreviewLayer(session: validCaptureSession)
self.previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
}
@ -746,7 +746,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
self.captureSession?.beginConfiguration()
let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
for device in devices {
let captureDevice = device as AVCaptureDevice
let captureDevice = device as! AVCaptureDevice
if (captureDevice.position == AVCaptureDevicePosition.Back) {
let avFlashMode = AVCaptureFlashMode(rawValue: flashMode.rawValue)
if (captureDevice.isFlashModeSupported(avFlashMode!)) {
@ -761,7 +761,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
private func _updateCameraQualityMode(newCameraOutputQuality: CameraOutputQuality)
{
if let validCaptureSession = self.captureSession? {
if let validCaptureSession = self.captureSession {
var sessionPreset = AVCaptureSessionPresetLow
switch (newCameraOutputQuality) {
case CameraOutputQuality.Low:

View File

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

View File

@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string></string>
<string>cameraDemo</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>

View File

@ -95,7 +95,7 @@ class ViewController: UIViewController {
self.cameraManager.capturePictureWithCompletition({ (image, error) -> Void in
let vc: ImageViewController? = self.storyboard?.instantiateViewControllerWithIdentifier("ImageVC") as? ImageViewController
if let validVC: ImageViewController = vc {
if let capturedImage = image? {
if let capturedImage = image {
validVC.image = capturedImage
self.navigationController?.pushViewController(validVC, animated: true)
}
@ -110,7 +110,7 @@ class ViewController: UIViewController {
} else {
self.cameraManager.stopRecordingVideo({ (videoURL, error) -> Void in
println(videoURL)
if let errorOccured = error? {
if let errorOccured = error {
UIAlertView(title: "Error occured", message: errorOccured.localizedDescription, delegate: nil, cancelButtonTitle: "OK").show()
}
})