commit 73231be8c8eff6f37dade126c2f0efff666c42cc Author: nelanelanela Date: Mon Oct 13 10:07:55 2014 +0100 Initial commit. diff --git a/camera.xcodeproj/project.pbxproj b/camera.xcodeproj/project.pbxproj new file mode 100644 index 0000000..e0c46e3 --- /dev/null +++ b/camera.xcodeproj/project.pbxproj @@ -0,0 +1,321 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 454C1F4719E82E2500C81915 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454C1F4619E82E2500C81915 /* AppDelegate.swift */; }; + 454C1F4919E82E2500C81915 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454C1F4819E82E2500C81915 /* ViewController.swift */; }; + 454C1F4C19E82E2500C81915 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 454C1F4A19E82E2500C81915 /* Main.storyboard */; }; + 454C1F4E19E82E2500C81915 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 454C1F4D19E82E2500C81915 /* Images.xcassets */; }; + 454C1F5119E82E2500C81915 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 454C1F4F19E82E2500C81915 /* LaunchScreen.xib */; }; + 454C1F6719E8316A00C81915 /* CameraManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 454C1F6619E8316A00C81915 /* CameraManager.swift */; }; +/* End PBXBuildFile 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 = ""; }; + 454C1F4619E82E2500C81915 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 454C1F4819E82E2500C81915 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 454C1F4B19E82E2500C81915 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 454C1F4D19E82E2500C81915 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + 454C1F5019E82E2500C81915 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + 454C1F5B19E82E2500C81915 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 454C1F5C19E82E2500C81915 /* cameraTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = cameraTests.swift; sourceTree = ""; }; + 454C1F6619E8316A00C81915 /* CameraManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraManager.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 454C1F3E19E82E2500C81915 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 454C1F3819E82E2500C81915 = { + isa = PBXGroup; + children = ( + 454C1F4319E82E2500C81915 /* camera */, + 454C1F5919E82E2500C81915 /* cameraTests */, + 454C1F4219E82E2500C81915 /* Products */, + ); + sourceTree = ""; + }; + 454C1F4219E82E2500C81915 /* Products */ = { + isa = PBXGroup; + children = ( + 454C1F4119E82E2500C81915 /* camera.app */, + ); + name = Products; + sourceTree = ""; + }; + 454C1F4319E82E2500C81915 /* camera */ = { + isa = PBXGroup; + children = ( + 454C1F4619E82E2500C81915 /* AppDelegate.swift */, + 454C1F6619E8316A00C81915 /* CameraManager.swift */, + 454C1F4819E82E2500C81915 /* ViewController.swift */, + 454C1F4A19E82E2500C81915 /* Main.storyboard */, + 454C1F4D19E82E2500C81915 /* Images.xcassets */, + 454C1F4F19E82E2500C81915 /* LaunchScreen.xib */, + 454C1F4419E82E2500C81915 /* Supporting Files */, + ); + path = camera; + sourceTree = ""; + }; + 454C1F4419E82E2500C81915 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 454C1F4519E82E2500C81915 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 454C1F5919E82E2500C81915 /* cameraTests */ = { + isa = PBXGroup; + children = ( + 454C1F5C19E82E2500C81915 /* cameraTests.swift */, + 454C1F5A19E82E2500C81915 /* Supporting Files */, + ); + path = cameraTests; + sourceTree = ""; + }; + 454C1F5A19E82E2500C81915 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 454C1F5B19E82E2500C81915 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 454C1F4019E82E2500C81915 /* camera */ = { + isa = PBXNativeTarget; + buildConfigurationList = 454C1F6019E82E2500C81915 /* Build configuration list for PBXNativeTarget "camera" */; + buildPhases = ( + 454C1F3D19E82E2500C81915 /* Sources */, + 454C1F3E19E82E2500C81915 /* Frameworks */, + 454C1F3F19E82E2500C81915 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = camera; + productName = camera; + productReference = 454C1F4119E82E2500C81915 /* camera.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 454C1F3919E82E2500C81915 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0600; + ORGANIZATIONNAME = imaginaryCloud; + TargetAttributes = { + 454C1F4019E82E2500C81915 = { + CreatedOnToolsVersion = 6.0.1; + }; + }; + }; + buildConfigurationList = 454C1F3C19E82E2500C81915 /* Build configuration list for PBXProject "camera" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 454C1F3819E82E2500C81915; + productRefGroup = 454C1F4219E82E2500C81915 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 454C1F4019E82E2500C81915 /* camera */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 454C1F3F19E82E2500C81915 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 454C1F4C19E82E2500C81915 /* Main.storyboard in Resources */, + 454C1F5119E82E2500C81915 /* LaunchScreen.xib in Resources */, + 454C1F4E19E82E2500C81915 /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 454C1F3D19E82E2500C81915 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 454C1F4919E82E2500C81915 /* ViewController.swift in Sources */, + 454C1F6719E8316A00C81915 /* CameraManager.swift in Sources */, + 454C1F4719E82E2500C81915 /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 454C1F4A19E82E2500C81915 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 454C1F4B19E82E2500C81915 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 454C1F4F19E82E2500C81915 /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + 454C1F5019E82E2500C81915 /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 454C1F5E19E82E2500C81915 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer: Luis Diniz (HUX544ZBSL)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + PROVISIONING_PROFILE = "4d0a483e-6fa4-454e-a019-6ce6d8c6f307"; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 454C1F5F19E82E2500C81915 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + PROVISIONING_PROFILE = "4d0a483e-6fa4-454e-a019-6ce6d8c6f307"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 454C1F6119E82E2500C81915 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = camera/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 454C1F6219E82E2500C81915 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = camera/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 454C1F3C19E82E2500C81915 /* Build configuration list for PBXProject "camera" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 454C1F5E19E82E2500C81915 /* Debug */, + 454C1F5F19E82E2500C81915 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 454C1F6019E82E2500C81915 /* Build configuration list for PBXNativeTarget "camera" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 454C1F6119E82E2500C81915 /* Debug */, + 454C1F6219E82E2500C81915 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 454C1F3919E82E2500C81915 /* Project object */; +} diff --git a/camera.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/camera.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..0c81108 --- /dev/null +++ b/camera.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/camera.xcodeproj/project.xcworkspace/xcuserdata/nataliaterlecka.xcuserdatad/UserInterfaceState.xcuserstate b/camera.xcodeproj/project.xcworkspace/xcuserdata/nataliaterlecka.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..3797afc Binary files /dev/null and b/camera.xcodeproj/project.xcworkspace/xcuserdata/nataliaterlecka.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcschemes/camera.xcscheme b/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcschemes/camera.xcscheme new file mode 100644 index 0000000..1e2fb55 --- /dev/null +++ b/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcschemes/camera.xcscheme @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcschemes/xcschememanagement.plist b/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..c12d058 --- /dev/null +++ b/camera.xcodeproj/xcuserdata/nataliaterlecka.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + camera.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 454C1F4019E82E2500C81915 + + primary + + + 454C1F5519E82E2500C81915 + + primary + + + + + diff --git a/camera/AppDelegate.swift b/camera/AppDelegate.swift new file mode 100644 index 0000000..22ede34 --- /dev/null +++ b/camera/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// camera +// +// Created by Natalia Terlecka on 10/10/14. +// Copyright (c) 2014 imaginaryCloud. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + // Override point for customization after application launch. + return true + } + + 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. + // 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) { + // 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. + } + + 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. + } + + 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. + } + + func applicationWillTerminate(application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/camera/Base.lproj/LaunchScreen.xib b/camera/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..3d07e66 --- /dev/null +++ b/camera/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/camera/Base.lproj/Main.storyboard b/camera/Base.lproj/Main.storyboard new file mode 100644 index 0000000..89cc81c --- /dev/null +++ b/camera/Base.lproj/Main.storyboard @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/camera/CameraManager.swift b/camera/CameraManager.swift new file mode 100644 index 0000000..21c234e --- /dev/null +++ b/camera/CameraManager.swift @@ -0,0 +1,159 @@ +// +// CameraManager.swift +// camera +// +// Created by Natalia Terlecka on 10/10/14. +// Copyright (c) 2014 imaginaryCloud. All rights reserved. +// + +import UIKit +import AVFoundation + +private let _singletonSharedInstance = CameraManager() + +class CameraManager: NSObject { + + var captureSession: AVCaptureSession? + + private var sessionQueue: dispatch_queue_t = dispatch_queue_create("CameraSessionQueue", DISPATCH_QUEUE_SERIAL) + private var frontCamera: AVCaptureInput? + private var rearCamera: AVCaptureInput? + private var stillImageOutput: AVCaptureStillImageOutput? + private var previewLayer: AVCaptureVideoPreviewLayer? + private var cameraIsSetup = false + + class var sharedInstance: CameraManager { + return _singletonSharedInstance + } + + func addPreeviewLayerToView(view: UIView) + { + if self.cameraIsSetup { + self._addPreeviewLayerToView(view) + } else { + self._setupCamera({ Void -> Void in + self._addPreeviewLayerToView(view) + }) + } + } + + func capturePictureWithCompletition(imageCompletition: UIImage -> Void) + { + dispatch_async(self.sessionQueue, { + if let validStillImageOutput = self.stillImageOutput? { + validStillImageOutput.captureStillImageAsynchronouslyFromConnection(validStillImageOutput.connectionWithMediaType(AVMediaTypeVideo), completionHandler: { [weak self] (sample: CMSampleBuffer!, error: NSError!) -> Void in + if (error? != nil) { + dispatch_async(dispatch_get_main_queue(), { + if let weakSelf = self { + weakSelf._show("error", message: error.localizedDescription) + } + }) + } else { + let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sample) + imageCompletition(UIImage(data: imageData)) + } + }) + } + }) + } + + func startFollowingDeviceOrientation() + { + NSNotificationCenter.defaultCenter().addObserver(self, selector: "orientationChanged", name: UIDeviceOrientationDidChangeNotification, object: nil) + } + + func orientationChanged() + { + + } + + private func _setupCamera(completition: Void -> Void) + { + self._checkIfCameraIsAvailable() + + self.captureSession = AVCaptureSession() + self.captureSession?.sessionPreset = AVCaptureSessionPresetPhoto + + dispatch_async(sessionQueue, { + if let validCaptureSession = self.captureSession? { + validCaptureSession.beginConfiguration() + self._addVideoInput() + self._addStillImageOutput() + self._setupPreviewLayer() + validCaptureSession.commitConfiguration() + validCaptureSession.startRunning() + completition() + self.cameraIsSetup = true + } + }) + } + + private func _addPreeviewLayerToView(view: UIView) + { + dispatch_async(dispatch_get_main_queue(), { () -> Void in + self.previewLayer?.frame = view.layer.bounds + view.clipsToBounds = true + view.layer.addSublayer(self.previewLayer) + }) + } + + private func _checkIfCameraIsAvailable() + { + AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (cameraAvailable) -> Void in + if !cameraAvailable { + self._show("Camera unavailable", message: "The app does not have access to camera") + } + }) + } + + private func _addVideoInput() + { + var error: NSError? + + var videoFrontDevice: AVCaptureDevice? + var videoBackDevice: AVCaptureDevice? + for device: AnyObject in AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) { + if device.position == AVCaptureDevicePosition.Back { + videoBackDevice = device as? AVCaptureDevice + } else if device.position == AVCaptureDevicePosition.Front { + videoFrontDevice = device as? AVCaptureDevice + } + } + if let validVideoFrontDevice = videoFrontDevice? { + self.frontCamera = AVCaptureDeviceInput.deviceInputWithDevice(validVideoFrontDevice, error: &error) as AVCaptureDeviceInput + } + if let validVideoBackDevice = videoBackDevice? { + self.rearCamera = AVCaptureDeviceInput.deviceInputWithDevice(validVideoBackDevice, error: &error) as AVCaptureDeviceInput + if !(error != nil) { + if let validBackDevice = self.rearCamera? { + self.captureSession?.addInput(validBackDevice) + } + } + } + } + + private func _addStillImageOutput() + { + self.stillImageOutput = AVCaptureStillImageOutput() + if let validStillImageOutput = self.stillImageOutput? { + self.captureSession?.addOutput(self.stillImageOutput) + } + } + + private func _setupPreviewLayer() + { + self.previewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession) + self.previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill + } + + private func _show (title: String, message: String) + { + dispatch_async(dispatch_get_main_queue(), { () -> Void in + UIAlertView( + title: title, + message: message, + delegate: self, + cancelButtonTitle: "OK").show() + }) + } +} diff --git a/camera/Images.xcassets/AppIcon.appiconset/Contents.json b/camera/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..36d2c80 --- /dev/null +++ b/camera/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/camera/Info.plist b/camera/Info.plist new file mode 100644 index 0000000..db4e323 --- /dev/null +++ b/camera/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.dotzar.camera + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/camera/ViewController.swift b/camera/ViewController.swift new file mode 100644 index 0000000..f0a3992 --- /dev/null +++ b/camera/ViewController.swift @@ -0,0 +1,31 @@ +// +// ViewController.swift +// camera +// +// Created by Natalia Terlecka on 10/10/14. +// Copyright (c) 2014 imaginaryCloud. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + let cameraManager = CameraManager.sharedInstance + + override func viewDidLoad() { + super.viewDidLoad() + self.cameraManager.addPreeviewLayerToView(self.view) + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + + @IBAction func viewTapped(sender: UITapGestureRecognizer) { + self.cameraManager.capturePictureWithCompletition({ (image) -> Void in }) + } +} + + diff --git a/cameraTests/Info.plist b/cameraTests/Info.plist new file mode 100644 index 0000000..5782876 --- /dev/null +++ b/cameraTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.imaginarycloud.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/cameraTests/cameraTests.swift b/cameraTests/cameraTests.swift new file mode 100644 index 0000000..c178880 --- /dev/null +++ b/cameraTests/cameraTests.swift @@ -0,0 +1,36 @@ +// +// cameraTests.swift +// cameraTests +// +// Created by Natalia Terlecka on 10/10/14. +// Copyright (c) 2014 imaginaryCloud. All rights reserved. +// + +import UIKit +import XCTest + +class cameraTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + XCTAssert(true, "Pass") + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock() { + // Put the code you want to measure the time of here. + } + } + +}