diff --git a/Podfile b/Podfile index 77cfa72..f962121 100644 --- a/Podfile +++ b/Podfile @@ -1,14 +1,17 @@ # Uncomment the next line to define a global platform for your project -platform :ios, '13.0' +# platform :ios, '9.0' target 'fakestagram' do - # Comment the next line if you don't want to use dynamic frameworks + # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! + # Pods for fakestagram - pod 'SAMKeychain' +pod 'SAMKeychain' target 'fakestagramTests' do inherit! :search_paths pod 'DVR' + # Pods for testing end -end + +end \ No newline at end of file diff --git a/Podfile.lock b/Podfile.lock index 12505e8..b78c244 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -15,6 +15,6 @@ SPEC CHECKSUMS: DVR: 062c287b9dc613a84120e44640176e4ef3ecf943 SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c -PODFILE CHECKSUM: 02c21c317ba9be4fdecdfff242f3fa20e9b269bd +PODFILE CHECKSUM: 5f20627b56a905f9a7ea5dc594a4450b05e9922f -COCOAPODS: 1.8.3 +COCOAPODS: 1.8.4 diff --git a/fakestagram.xcodeproj/project.pbxproj b/fakestagram.xcodeproj/project.pbxproj index fd88dc7..d8bc53f 100644 --- a/fakestagram.xcodeproj/project.pbxproj +++ b/fakestagram.xcodeproj/project.pbxproj @@ -689,7 +689,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = D3XL2U7DQC; + DEVELOPMENT_TEAM = R83P3CD95H; INFOPLIST_FILE = fakestagram/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -711,7 +711,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = D3XL2U7DQC; + DEVELOPMENT_TEAM = R83P3CD95H; INFOPLIST_FILE = fakestagram/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/fakestagram/Base.lproj/Main.storyboard b/fakestagram/Base.lproj/Main.storyboard index 469596b..1cc815f 100644 --- a/fakestagram/Base.lproj/Main.storyboard +++ b/fakestagram/Base.lproj/Main.storyboard @@ -2,7 +2,7 @@ - + @@ -63,32 +63,44 @@ + - - - - + + + - - - - + + + + + + + + + + @@ -140,6 +152,7 @@ + diff --git a/fakestagram/ViewControllers/CameraViewController.swift b/fakestagram/ViewControllers/CameraViewController.swift index a7996c7..709fbf3 100644 --- a/fakestagram/ViewControllers/CameraViewController.swift +++ b/fakestagram/ViewControllers/CameraViewController.swift @@ -41,16 +41,24 @@ class CameraViewController: UIViewController { settings.flashMode = .auto photoOutput.capturePhoto(with: settings, delegate: self) } - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. - } - */ + + + @IBAction func switchCamera(_ sender: UIButton) { + guard let currentCameraInput: AVCaptureInput = session.inputs.first else { + return + } + + if let input = currentCameraInput as? AVCaptureDeviceInput { + if input.device.position == .back { + switchToFrontCamera() + } + + if input.device.position == .front { + switchToBackCamera() + } + } + } + // MARK: - CoreLocation methods let locationManager = CLLocationManager() @@ -71,6 +79,7 @@ class CameraViewController: UIViewController { // MARK: - AVFoundation methods @IBOutlet weak var previewView: PreviewView! + func enableCameraAccess() { switch AVCaptureDevice.authorizationStatus(for: .video) { case .authorized: @@ -94,15 +103,18 @@ class CameraViewController: UIViewController { } } - let session = AVCaptureSession() + var session = AVCaptureSession() let photoOutput = AVCapturePhotoOutput() + var videoPreviewLeyer = AVCaptureVideoPreviewLayer() + + var frontCamera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front) + var backCamera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) func setupCaptureSession() { session.beginConfiguration() - let device = AVCaptureDevice.default(.builtInDualCamera, - for: .video, position: .back)! + let device = backCamera! guard let videoDeviceInput = try? AVCaptureDeviceInput(device: device), - session.canAddInput(videoDeviceInput) else { return } + session.canAddInput(videoDeviceInput) else { return } session.addInput(videoDeviceInput) guard session.canAddOutput(photoOutput) else { return } @@ -114,6 +126,42 @@ class CameraViewController: UIViewController { session.startRunning() } + + func switchToFrontCamera () { + if frontCamera?.isConnected == true { + session.stopRunning() + let captureDevice = frontCamera + do { + let input = try AVCaptureDeviceInput(device: captureDevice!) + session = AVCaptureSession() + session.addInput(input) + videoPreviewLeyer = AVCaptureVideoPreviewLayer(session: session) + videoPreviewLeyer.frame = previewView.layer.bounds + previewView.layer.addSublayer(videoPreviewLeyer) + session.startRunning() + } catch { + print("Error") + } + } + } + + func switchToBackCamera () { + if frontCamera?.isConnected == true { + session.stopRunning() + let captureDevice = backCamera + do { + let input = try AVCaptureDeviceInput(device: captureDevice!) + session = AVCaptureSession() + session.addInput(input) + videoPreviewLeyer = AVCaptureVideoPreviewLayer(session: session) + videoPreviewLeyer.frame = previewView.layer.bounds + previewView.layer.addSublayer(videoPreviewLeyer) + session.startRunning() + } catch { + print("Error") + } + } + } }