Skip to content

Commit 91bd7db

Browse files
committed
Implement camera view controller
1 parent b59c0af commit 91bd7db

File tree

10 files changed

+538
-372
lines changed

10 files changed

+538
-372
lines changed

BarcodeScanner.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
D50BE3EB1C9FE7A80000A34C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = D50BE3E71C9FE7A80000A34C /* [email protected] */; };
1515
D55281B62016758F00FF3CDD /* HeaderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55281B52016758F00FF3CDD /* HeaderViewController.swift */; };
1616
D55281B8201675D500FF3CDD /* MessageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55281B7201675D500FF3CDD /* MessageViewController.swift */; };
17-
D55281BA2016770800FF3CDD /* VideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55281B92016770800FF3CDD /* VideoViewController.swift */; };
17+
D55281BA2016770800FF3CDD /* CameraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55281B92016770800FF3CDD /* CameraViewController.swift */; };
1818
D55281BC2016782C00FF3CDD /* ScannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55281BB2016782C00FF3CDD /* ScannerViewController.swift */; };
1919
D55281BF20167DB400FF3CDD /* UIViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55281BE20167DB400FF3CDD /* UIViewController+Extensions.swift */; };
2020
D55281C720168E7000FF3CDD /* NSLayoutConstraint+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55281C620168E7000FF3CDD /* NSLayoutConstraint+Extensions.swift */; };
2121
D5C4E08E1CA0BFB9008D9269 /* InfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C4E08C1CA0BFB9008D9269 /* InfoView.swift */; };
2222
D5C4E08F1CA0BFB9008D9269 /* TorchMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C4E08D1CA0BFB9008D9269 /* TorchMode.swift */; };
23+
D5CB377F2017ED2E00B9319D /* VideoPermissionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5CB377E2017ED2E00B9319D /* VideoPermissionService.swift */; };
2324
D5F1C1C91C9C5113001E17A6 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F1C1C51C9C5113001E17A6 /* Config.swift */; };
2425
D5F1C1CA1C9C5113001E17A6 /* BarcodeScannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F1C1C61C9C5113001E17A6 /* BarcodeScannerController.swift */; };
2526
D5F1C1D31C9C5809001E17A6 /* HeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F1C1D21C9C5809001E17A6 /* HeaderView.swift */; };
@@ -34,14 +35,15 @@
3435
D50BE3E71C9FE7A80000A34C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
3536
D55281B52016758F00FF3CDD /* HeaderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderViewController.swift; sourceTree = "<group>"; };
3637
D55281B7201675D500FF3CDD /* MessageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageViewController.swift; sourceTree = "<group>"; };
37-
D55281B92016770800FF3CDD /* VideoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoViewController.swift; sourceTree = "<group>"; };
38+
D55281B92016770800FF3CDD /* CameraViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraViewController.swift; sourceTree = "<group>"; };
3839
D55281BB2016782C00FF3CDD /* ScannerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerViewController.swift; sourceTree = "<group>"; };
3940
D55281BE20167DB400FF3CDD /* UIViewController+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extensions.swift"; sourceTree = "<group>"; };
4041
D55281C620168E7000FF3CDD /* NSLayoutConstraint+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSLayoutConstraint+Extensions.swift"; sourceTree = "<group>"; };
4142
D5B2E89F1C3A780C00C0327D /* BarcodeScanner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = BarcodeScanner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4243
D5C4E08C1CA0BFB9008D9269 /* InfoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = InfoView.swift; sourceTree = "<group>"; tabWidth = 2; };
4344
D5C4E08D1CA0BFB9008D9269 /* TorchMode.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = TorchMode.swift; sourceTree = "<group>"; tabWidth = 2; };
4445
D5C6298B1C3A8BBD007F7B7C /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = "<group>"; };
46+
D5CB377E2017ED2E00B9319D /* VideoPermissionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPermissionService.swift; sourceTree = "<group>"; };
4547
D5F1C1C51C9C5113001E17A6 /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; tabWidth = 2; };
4648
D5F1C1C61C9C5113001E17A6 /* BarcodeScannerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = BarcodeScannerController.swift; sourceTree = "<group>"; tabWidth = 2; };
4749
D5F1C1D21C9C5809001E17A6 /* HeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = HeaderView.swift; sourceTree = "<group>"; tabWidth = 2; };
@@ -75,7 +77,7 @@
7577
D5F1C1C61C9C5113001E17A6 /* BarcodeScannerController.swift */,
7678
D55281B52016758F00FF3CDD /* HeaderViewController.swift */,
7779
D55281B7201675D500FF3CDD /* MessageViewController.swift */,
78-
D55281B92016770800FF3CDD /* VideoViewController.swift */,
80+
D55281B92016770800FF3CDD /* CameraViewController.swift */,
7981
D55281BB2016782C00FF3CDD /* ScannerViewController.swift */,
8082
);
8183
path = Controllers;
@@ -128,6 +130,7 @@
128130
2DBF9E0D1F169DEF006B5AA8 /* FocusViewType.swift */,
129131
D5F1C1C51C9C5113001E17A6 /* Config.swift */,
130132
D5F1C1D21C9C5809001E17A6 /* HeaderView.swift */,
133+
D5CB377E2017ED2E00B9319D /* VideoPermissionService.swift */,
131134
);
132135
path = Sources;
133136
sourceTree = "<group>";
@@ -217,12 +220,13 @@
217220
D55281C720168E7000FF3CDD /* NSLayoutConstraint+Extensions.swift in Sources */,
218221
D5C4E08E1CA0BFB9008D9269 /* InfoView.swift in Sources */,
219222
D55281BF20167DB400FF3CDD /* UIViewController+Extensions.swift in Sources */,
220-
D55281BA2016770800FF3CDD /* VideoViewController.swift in Sources */,
223+
D55281BA2016770800FF3CDD /* CameraViewController.swift in Sources */,
221224
D5F1C1D31C9C5809001E17A6 /* HeaderView.swift in Sources */,
222225
D5F1C1C91C9C5113001E17A6 /* Config.swift in Sources */,
223226
D55281B8201675D500FF3CDD /* MessageViewController.swift in Sources */,
224227
D5F1C1CA1C9C5113001E17A6 /* BarcodeScannerController.swift in Sources */,
225228
D55281BC2016782C00FF3CDD /* ScannerViewController.swift in Sources */,
229+
D5CB377F2017ED2E00B9319D /* VideoPermissionService.swift in Sources */,
226230
2DBF9E0E1F169DEF006B5AA8 /* FocusViewType.swift in Sources */,
227231
D504555F1FD8714700E46826 /* UIView+Extensions.swift in Sources */,
228232
D5FC8AD71D252A12004BED88 /* State.swift in Sources */,

Example/BarcodeScannerExample/BarcodeScannerExample/ViewController.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ class ViewController: UIViewController {
66
@IBOutlet var presentScannerButton: UIButton!
77
@IBOutlet var pushScannerButton: UIButton!
88

9-
private let controller = ScannerController()
10-
11-
override func viewDidLoad() {
12-
super.viewDidLoad()
13-
14-
controller.codeDelegate = self
15-
controller.errorDelegate = self
16-
controller.dismissalDelegate = self
17-
}
18-
199
@IBAction func handleScannerPresent(_ sender: Any, forEvent event: UIEvent) {
10+
let controller = makeBarcodeScannerController()
2011
controller.title = "Barcode Scanner"
2112
present(controller, animated: true, completion: nil)
2213
}
2314

2415
@IBAction func handleScannerPush(_ sender: Any, forEvent event: UIEvent) {
16+
let controller = makeBarcodeScannerController()
2517
controller.title = "Barcode Scanner"
2618
navigationController?.pushViewController(controller, animated: true)
2719
}
20+
21+
private func makeBarcodeScannerController() -> ScannerController {
22+
let controller = ScannerController()
23+
controller.codeDelegate = self
24+
controller.errorDelegate = self
25+
controller.dismissalDelegate = self
26+
return controller
27+
}
2828
}
2929

3030
extension ViewController: ScannerCodeDelegate {

Sources/Config.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ func localizedString(_ key: String) -> String {
6969
return key
7070
}
7171

72+
var isSimulatorRunning: Bool = {
73+
#if (arch(i386) || arch(x86_64)) && os(iOS)
74+
return true
75+
#else
76+
return false
77+
#endif
78+
}()
79+
7280
/**
7381
`AVCaptureMetadataOutput` metadata object types.
7482
*/

0 commit comments

Comments
 (0)