Syntax updated for Swift 2.0

This commit is contained in:
Natalia Terlecka 2015-07-30 14:04:15 +01:00
parent 0c0a90fe17
commit 68858dfb4b
9 changed files with 63 additions and 39 deletions

View File

@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>

View File

@ -1,3 +0,0 @@
platform :ios, '8.0'
pod 'CameraManager', :git => 'https://gist.github.com/2204678.git'

View File

@ -202,7 +202,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0600;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = imaginaryCloud;
TargetAttributes = {
454C1F4019E82E2500C81915 = {
@ -323,6 +323,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
@ -389,6 +390,7 @@
INFOPLIST_FILE = camera/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = cameraDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@ -400,6 +402,7 @@
INFOPLIST_FILE = camera/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = cameraDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
@ -422,6 +425,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
VERSIONING_SYSTEM = "apple-generic";
@ -444,6 +448,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
VERSIONING_SYSTEM = "apple-generic";

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@ -29,6 +29,8 @@
buildConfiguration = "Debug">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
@ -38,6 +40,7 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0600"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@ -62,6 +62,8 @@
ReferencedContainer = "container:camera.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
@ -71,8 +73,10 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "454C1F4019E82E2500C81915"
@ -90,7 +94,8 @@
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "454C1F4019E82E2500C81915"

View File

@ -109,24 +109,24 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
case .Front:
if self.hasFrontCamera {
if let validBackDevice = self.rearCamera {
if contains(inputs, validBackDevice) {
if inputs.contains(validBackDevice) {
validCaptureSession.removeInput(validBackDevice)
}
}
if let validFrontDevice = self.frontCamera {
if !contains(inputs, validFrontDevice) {
if !inputs.contains(validFrontDevice) {
validCaptureSession.addInput(validFrontDevice)
}
}
}
case .Back:
if let validFrontDevice = self.frontCamera {
if contains(inputs, validFrontDevice) {
if inputs.contains(validFrontDevice) {
validCaptureSession.removeInput(validFrontDevice)
}
}
if let validBackDevice = self.rearCamera {
if !contains(inputs, validBackDevice) {
if !inputs.contains(validBackDevice) {
validCaptureSession.addInput(validBackDevice)
}
}
@ -201,9 +201,13 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
private var tempFilePath: NSURL = {
let tempPath = NSTemporaryDirectory().stringByAppendingPathComponent("tempMovie").stringByAppendingPathExtension("mp4")
if NSFileManager.defaultManager().fileExistsAtPath(tempPath!) {
NSFileManager.defaultManager().removeItemAtPath(tempPath!, error: nil)
do {
try NSFileManager.defaultManager().removeItemAtPath(tempPath!)
} catch {
}
}
return NSURL(fileURLWithPath: tempPath!)!
return NSURL(fileURLWithPath: tempPath!)
}()
@ -224,7 +228,7 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
public func addPreviewLayerToView(view: UIView, newCameraOutputMode: CameraOutputMode) -> CameraState
{
if self._canLoadCamera() {
if let validEmbedingView = self.embedingView {
if let _ = self.embedingView {
if let validPreviewLayer = self.previewLayer {
validPreviewLayer.removeFromSuperlayer()
}
@ -466,7 +470,11 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
if (captureDevice.position == AVCaptureDevicePosition.Back) {
let avTorchMode = AVCaptureTorchMode(rawValue: flashMode.rawValue)
if (captureDevice.isTorchModeSupported(avTorchMode!)) {
captureDevice.lockForConfiguration(nil)
do {
try captureDevice.lockForConfiguration()
} catch {
return;
}
captureDevice.torchMode = avTorchMode!
captureDevice.unlockForConfiguration()
}
@ -612,9 +620,12 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
{
self.embedingView = view
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.previewLayer?.frame = view.layer.bounds
guard let _ = self.previewLayer else {
return
}
self.previewLayer!.frame = view.layer.bounds
view.clipsToBounds = true
view.layer.addSublayer(self.previewLayer)
view.layer.addSublayer(self.previewLayer!)
})
}
@ -640,8 +651,6 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
private func _addVideoInput()
{
var error: NSError?
if (self.frontCamera == nil) || (self.rearCamera == nil) {
var videoFrontDevice: AVCaptureDevice?
var videoBackDevice: AVCaptureDevice?
@ -652,18 +661,20 @@ 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
do {
if (self.frontCamera == nil) {
if let validVideoFrontDevice = videoFrontDevice {
try self.frontCamera = AVCaptureDeviceInput(device: validVideoFrontDevice)
}
}
}
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 {
try self.rearCamera = AVCaptureDeviceInput(device: validVideoBackDevice)
}
}
}
if let validError = error {
self._show(NSLocalizedString("Device setup error occured", comment:""), message: validError.localizedDescription)
} catch let outError {
self._show(NSLocalizedString("Device setup error occured", comment:""), message: "\(outError)")
return
}
}
self.cameraDevice = _cameraDevice
@ -672,12 +683,12 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
private func _setupMic()
{
if (self.mic == nil) {
var error: NSError?
let micDevice:AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio);
self.mic = AVCaptureDeviceInput.deviceInputWithDevice(micDevice, error: &error) as? AVCaptureDeviceInput;
if let errorHappened = error {
let micDevice:AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)
do {
try self.mic = AVCaptureDeviceInput(device: micDevice)
} catch let outError {
self.mic = nil
self._show(NSLocalizedString("Mic error", comment:""), message: errorHappened.description)
self._show(NSLocalizedString("Mic error", comment:""), message: "\(outError)")
}
}
}
@ -762,7 +773,11 @@ public class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate {
if (captureDevice.position == AVCaptureDevicePosition.Back) {
let avFlashMode = AVCaptureFlashMode(rawValue: flashMode.rawValue)
if (captureDevice.isFlashModeSupported(avFlashMode!)) {
captureDevice.lockForConfiguration(nil)
do {
try captureDevice.lockForConfiguration()
} catch {
return
}
captureDevice.flashMode = avFlashMode!
captureDevice.unlockForConfiguration()
}

View File

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

View File

@ -124,7 +124,6 @@ class ViewController: UIViewController {
self.cameraManager.startRecordingVideo()
} else {
self.cameraManager.stopRecordingVideo({ (videoURL, error) -> Void in
println(videoURL)
if let errorOccured = error {
self.cameraManager.showErrorBlock(erTitle: "Error occurred", erMessage: errorOccured.localizedDescription)
}