diff --git a/README.md b/README.md index a145d4d..e2b784d 100755 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ V1.0.0 (10-Oct-2014) ####About -This is a simple class to provide all the configurations you need to create custom camera view in your app. +This is a simple class to provide all the configurations and you need to create custom camera view in your app. Just drag, drop and use. ####How to use diff --git a/camera.xcodeproj/project.pbxproj b/camera.xcodeproj/project.pbxproj index e0c46e3..40eaa43 100644 --- a/camera.xcodeproj/project.pbxproj +++ b/camera.xcodeproj/project.pbxproj @@ -23,8 +23,6 @@ 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 */ @@ -43,7 +41,6 @@ isa = PBXGroup; children = ( 454C1F4319E82E2500C81915 /* camera */, - 454C1F5919E82E2500C81915 /* cameraTests */, 454C1F4219E82E2500C81915 /* Products */, ); sourceTree = ""; @@ -78,23 +75,6 @@ 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 */ @@ -314,6 +294,7 @@ 454C1F6219E82E2500C81915 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/camera.xcodeproj/project.xcworkspace/xcshareddata/camera.xccheckout b/camera.xcodeproj/project.xcworkspace/xcshareddata/camera.xccheckout new file mode 100644 index 0000000..eac38a0 --- /dev/null +++ b/camera.xcodeproj/project.xcworkspace/xcshareddata/camera.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + B6656DA7-2538-41EB-B435-476DC073ECE9 + IDESourceControlProjectName + camera + IDESourceControlProjectOriginsDictionary + + E1D0A3AE6B49B031DF6A25973E5414F28D2A575A + https://github.com/imaginary-cloud/CameraManager.git + + IDESourceControlProjectPath + camera.xcodeproj + IDESourceControlProjectRelativeInstallPathDictionary + + E1D0A3AE6B49B031DF6A25973E5414F28D2A575A + ../.. + + IDESourceControlProjectURL + https://github.com/imaginary-cloud/CameraManager.git + IDESourceControlProjectVersion + 111 + IDESourceControlProjectWCCIdentifier + E1D0A3AE6B49B031DF6A25973E5414F28D2A575A + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + E1D0A3AE6B49B031DF6A25973E5414F28D2A575A + IDESourceControlWCCName + camera + + + + diff --git a/camera.xcodeproj/project.xcworkspace/xcuserdata/nataliaterlecka.xcuserdatad/UserInterfaceState.xcuserstate b/camera.xcodeproj/project.xcworkspace/xcuserdata/nataliaterlecka.xcuserdatad/UserInterfaceState.xcuserstate index 9307480..edc8bdd 100644 Binary files a/camera.xcodeproj/project.xcworkspace/xcuserdata/nataliaterlecka.xcuserdatad/UserInterfaceState.xcuserstate and b/camera.xcodeproj/project.xcworkspace/xcuserdata/nataliaterlecka.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/camera/CameraManager.swift b/camera/CameraManager.swift index 2dc0132..b5a27fe 100644 --- a/camera/CameraManager.swift +++ b/camera/CameraManager.swift @@ -34,8 +34,13 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate { /// Capture sessioc to customize camera settings. var captureSession: AVCaptureSession? - /// Property to determine if the manager should show the error for the user. + /// 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 var showErrorsToUsers = true + + /// A block creating UI to present error message to the user. + var showErrorBlock:(erTitle: String, erMessage: String) -> Void = { (erTitle: String, erMessage: String) -> Void in + UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show() + } /// The Bool property to determin if current device has front camera. var hasFrontCamera: Bool = { @@ -49,11 +54,6 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate { return false }() - /// A block creating UI to present error message to the user. - var showErrorBlock:(erTitle: String, erMessage: String) -> Void = { (erTitle: String, erMessage: String) -> Void in - UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show() - } - /// Property to change camera device between front and back. var cameraDevice: CameraDevice { get { @@ -175,7 +175,7 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate { switch newCameraOutputMode { case .StillImage: if (self.stillImageOutput == nil) { - self._setupStillImageOutput() + self._setupOutputs() } if let validStillImageOutput = self.stillImageOutput? { self.captureSession?.addOutput(validStillImageOutput) @@ -184,7 +184,7 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate { case .VideoOnly, .VideoWithMic: if (self.movieOutput == nil) { - self._setupMovieOutput() + self._setupOutputs() } if let validMovieOutput = self.movieOutput? { self.captureSession?.addOutput(validMovieOutput) @@ -250,7 +250,11 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate { :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 */ - func addPreeviewLayerToView(view: UIView, cameraOutputMode: CameraOutputMode) + func addPreeviewLayerToView(view: UIView) + { + self.addPreeviewLayerToView(view, newCameraOutputMode: self.currentCameraOutputMode) + } + func addPreeviewLayerToView(view: UIView, newCameraOutputMode: CameraOutputMode) { if let validEmbedingView = self.embedingView? { if let validPreviewLayer = self.previewLayer? { @@ -259,11 +263,11 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate { } if self.cameraIsSetup { self._addPreeviewLayerToView(view) - self.cameraOutputMode = cameraOutputMode + self.cameraOutputMode = newCameraOutputMode } else { self._setupCamera({ Void -> Void in self._addPreeviewLayerToView(view) - self.cameraOutputMode = cameraOutputMode + self.cameraOutputMode = newCameraOutputMode }) } } @@ -413,8 +417,7 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate { if let validCaptureSession = self.captureSession? { validCaptureSession.beginConfiguration() self._addVideoInput() - self._setupStillImageOutput() - self._setupMovieOutput() + self._setupOutputs() self.cameraOutputMode = self.currentCameraOutputMode self._setupPreviewLayer() validCaptureSession.commitConfiguration() @@ -494,20 +497,16 @@ class CameraManager: NSObject, AVCaptureFileOutputRecordingDelegate { } } - private func _setupStillImageOutput() + private func _setupOutputs() { if (self.stillImageOutput == nil) { self.stillImageOutput = AVCaptureStillImageOutput() } - } - - private func _setupMovieOutput() - { if (self.movieOutput == nil) { self.movieOutput = AVCaptureMovieFileOutput() } } - + private func _setupPreviewLayer() { if let validCaptureSession = self.captureSession? { diff --git a/camera/ViewController.swift b/camera/ViewController.swift index e9dd6ff..7b722f7 100644 --- a/camera/ViewController.swift +++ b/camera/ViewController.swift @@ -18,10 +18,14 @@ class ViewController: UIViewController { override func viewDidLoad() { - super.viewDidLoad() - self.cameraManager.addPreeviewLayerToView(self.cameraView, cameraOutputMode: CameraOutputMode.VideoWithMic) + super.viewDidLoad() + self.cameraManager.addPreeviewLayerToView(self.cameraView, newCameraOutputMode: CameraOutputMode.VideoWithMic) + CameraManager.sharedInstance.addPreeviewLayerToView(self.cameraView) self.cameraManager.cameraDevice = .Front self.imageView.hidden = true + CameraManager.sharedInstance.showErrorBlock = { (erTitle: String, erMessage: String) -> Void in + UIAlertView(title: erTitle, message: erMessage, delegate: nil, cancelButtonTitle: "OK").show() + } } @IBAction func changeFlashMode(sender: UIButton)