Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Podfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ SPEC CHECKSUMS:
DVR: 062c287b9dc613a84120e44640176e4ef3ecf943
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c

PODFILE CHECKSUM: 02c21c317ba9be4fdecdfff242f3fa20e9b269bd
PODFILE CHECKSUM: 5f20627b56a905f9a7ea5dc594a4450b05e9922f

COCOAPODS: 1.8.3
COCOAPODS: 1.8.4
4 changes: 2 additions & 2 deletions fakestagram.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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)",
Expand Down
53 changes: 33 additions & 20 deletions fakestagram/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="If5-ZY-Hbn">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15509"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="collection view cell content view" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -63,32 +63,44 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9Q4-Cd-Jrr">
<rect key="frame" x="44" y="749" width="177" height="40.5"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<state key="normal" title="Capture"/>
<connections>
<action selector="onTapCreate:" destination="Tt7-wh-Hav" eventType="touchUpInside" id="Mqj-P2-wsr"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dsV-RX-7j3" customClass="PreviewView" customModule="fakestagram" customModuleProvider="target">
<rect key="frame" x="0.0" y="44" width="414" height="769"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9Q4-Cd-Jrr">
<rect key="frame" x="20" y="703" width="374" height="41"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<state key="normal" title="Capture"/>
<connections>
<action selector="onTapCreate:" destination="Tt7-wh-Hav" eventType="touchUpInside" id="Mqj-P2-wsr"/>
</connections>
</button>
</subviews>
<rect key="frame" x="0.0" y="44" width="414" height="692"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2C8-xB-Ofm">
<rect key="frame" x="286" y="758" width="36" height="22.5"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="9Q4-Cd-Jrr" secondAttribute="bottom" constant="25" id="9b8-Nw-vWe"/>
<constraint firstAttribute="trailing" secondItem="9Q4-Cd-Jrr" secondAttribute="trailing" constant="20" id="9ni-n1-GFK"/>
<constraint firstItem="9Q4-Cd-Jrr" firstAttribute="leading" secondItem="dsV-RX-7j3" secondAttribute="leading" constant="20" id="gFc-M1-ufz"/>
<constraint firstAttribute="height" constant="22.5" id="Pcb-Ld-fhX"/>
<constraint firstAttribute="width" constant="36" id="x9c-Ec-7gS"/>
</constraints>
</view>
<state key="normal" title="Button" image="camera.rotate.fill" catalog="system">
<preferredSymbolConfiguration key="preferredSymbolConfiguration" scale="large"/>
</state>
<connections>
<action selector="switchCamera:" destination="Tt7-wh-Hav" eventType="touchUpInside" id="bzu-2o-7AG"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="dsV-RX-7j3" firstAttribute="bottom" secondItem="N1S-7H-YSJ" secondAttribute="bottom" id="0it-cv-PHD"/>
<constraint firstItem="dsV-RX-7j3" firstAttribute="leading" secondItem="N1S-7H-YSJ" secondAttribute="leading" id="Ipp-tq-VSv"/>
<constraint firstItem="dsV-RX-7j3" firstAttribute="trailing" secondItem="N1S-7H-YSJ" secondAttribute="trailing" id="edS-Iu-DTF"/>
<constraint firstItem="dsV-RX-7j3" firstAttribute="top" secondItem="N1S-7H-YSJ" secondAttribute="top" id="uvD-97-5Rp"/>
<constraint firstItem="dsV-RX-7j3" firstAttribute="centerX" secondItem="O6d-4y-Gvs" secondAttribute="centerX" id="Gls-z8-Wfh"/>
<constraint firstItem="N1S-7H-YSJ" firstAttribute="trailing" secondItem="2C8-xB-Ofm" secondAttribute="trailing" constant="92" id="Ksw-jP-0hX"/>
<constraint firstItem="9Q4-Cd-Jrr" firstAttribute="leading" secondItem="N1S-7H-YSJ" secondAttribute="leading" constant="44" id="Q82-Fg-GfT"/>
<constraint firstItem="2C8-xB-Ofm" firstAttribute="top" secondItem="dsV-RX-7j3" secondAttribute="bottom" constant="22" id="Upp-hU-iw9"/>
<constraint firstItem="9Q4-Cd-Jrr" firstAttribute="centerY" secondItem="2C8-xB-Ofm" secondAttribute="centerY" id="dAB-Ux-1s4"/>
<constraint firstItem="9Q4-Cd-Jrr" firstAttribute="top" secondItem="dsV-RX-7j3" secondAttribute="bottom" constant="13" id="e01-Tn-Raf"/>
<constraint firstItem="2C8-xB-Ofm" firstAttribute="leading" secondItem="9Q4-Cd-Jrr" secondAttribute="trailing" constant="65" id="nz4-gG-WoD"/>
<constraint firstItem="dsV-RX-7j3" firstAttribute="top" secondItem="N1S-7H-YSJ" secondAttribute="top" id="r8v-7d-tsR"/>
<constraint firstItem="N1S-7H-YSJ" firstAttribute="bottom" secondItem="9Q4-Cd-Jrr" secondAttribute="bottom" constant="23.5" id="uUz-xA-hX9"/>
<constraint firstItem="dsV-RX-7j3" firstAttribute="leading" secondItem="N1S-7H-YSJ" secondAttribute="leading" id="vKr-2r-RmD"/>
</constraints>
<viewLayoutGuide key="safeArea" id="N1S-7H-YSJ"/>
</view>
Expand Down Expand Up @@ -140,6 +152,7 @@
</scenes>
<resources>
<image name="approval" width="30" height="30"/>
<image name="camera.rotate.fill" catalog="system" width="64" height="48"/>
<image name="person.circle" catalog="system" width="64" height="60"/>
<image name="plus.rectangle" catalog="system" width="64" height="46"/>
</resources>
Expand Down
76 changes: 62 additions & 14 deletions fakestagram/ViewControllers/CameraViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -71,6 +79,7 @@ class CameraViewController: UIViewController {
// MARK: - AVFoundation methods

@IBOutlet weak var previewView: PreviewView!

func enableCameraAccess() {
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized:
Expand All @@ -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 }
Expand All @@ -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")
}
}
}

}

Expand Down