Skip to content

Commit 4900440

Browse files
Merge pull request #54 from regulaforensics/6.4-sample
Release 6.4
2 parents c746c2b + 9592989 commit 4900440

12 files changed

Lines changed: 349 additions & 12 deletions

File tree

Samples/Advanced/DocumentReader-Swift/DocumentReader-Swift.xcodeproj/project.pbxproj

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@
4444
9D9560B225D1805E00C0673F /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9560B125D1805E00C0673F /* SettingsViewController.swift */; };
4545
9D9560B725D286D100C0673F /* SettingsSwitchCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9560B525D286D100C0673F /* SettingsSwitchCell.swift */; };
4646
9D9560B825D286D100C0673F /* SettingsSwitchCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9D9560B625D286D100C0673F /* SettingsSwitchCell.xib */; };
47+
9D969824284A0BB20005C1BD /* ir.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 9D969821284A0BB20005C1BD /* ir.bmp */; };
48+
9D969825284A0BB20005C1BD /* uv.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 9D969822284A0BB20005C1BD /* uv.bmp */; };
49+
9D969826284A0BB20005C1BD /* white.bmp in Resources */ = {isa = PBXBuildFile; fileRef = 9D969823284A0BB20005C1BD /* white.bmp */; };
4750
9D9F7DB325D56E9B0091C675 /* LCID+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9F7DB225D56E9B0091C675 /* LCID+Extensions.swift */; };
4851
9D9F7DB725D573620091C675 /* GetValuesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D9F7DB625D573620091C675 /* GetValuesViewController.swift */; };
52+
9DA9A410283693DC0063B00E /* layer.json in Resources */ = {isa = PBXBuildFile; fileRef = 9DA9A40F283693DC0063B00E /* layer.json */; };
53+
9DA9A413283780450063B00E /* CustomUIModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DA9A412283780450063B00E /* CustomUIModels.swift */; };
4954
9DC45D3025D692AC0077AE4A /* DocReaderFrame+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DC45D2F25D692AC0077AE4A /* DocReaderFrame+Extensions.swift */; };
5055
9DF08E5225D3C9C700880F7E /* SettingsActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DF08E5025D3C9C700880F7E /* SettingsActionCell.swift */; };
5156
9DF08E5325D3C9C700880F7E /* SettingsActionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9DF08E5125D3C9C700880F7E /* SettingsActionCell.xib */; };
@@ -55,6 +60,19 @@
5560
D1409041612445C6ECC23CA8 /* Pods_DocumentReader_Swift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0DC5DA1B48C6A7B2425AF7F0 /* Pods_DocumentReader_Swift.framework */; };
5661
/* End PBXBuildFile section */
5762

63+
/* Begin PBXCopyFilesBuildPhase section */
64+
9DA9A40C283692830063B00E /* Embed Frameworks */ = {
65+
isa = PBXCopyFilesBuildPhase;
66+
buildActionMask = 2147483647;
67+
dstPath = "";
68+
dstSubfolderSpec = 10;
69+
files = (
70+
);
71+
name = "Embed Frameworks";
72+
runOnlyForDeploymentPostprocessing = 0;
73+
};
74+
/* End PBXCopyFilesBuildPhase section */
75+
5876
/* Begin PBXFileReference section */
5977
0BBE1365BE97A7AE1B68DF58 /* Pods-DocumentReader-Swift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocumentReader-Swift.release.xcconfig"; path = "Target Support Files/Pods-DocumentReader-Swift/Pods-DocumentReader-Swift.release.xcconfig"; sourceTree = "<group>"; };
6078
0DC5DA1B48C6A7B2425AF7F0 /* Pods_DocumentReader_Swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DocumentReader_Swift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -99,8 +117,13 @@
99117
9D9560B125D1805E00C0673F /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
100118
9D9560B525D286D100C0673F /* SettingsSwitchCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSwitchCell.swift; sourceTree = "<group>"; };
101119
9D9560B625D286D100C0673F /* SettingsSwitchCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsSwitchCell.xib; sourceTree = "<group>"; };
120+
9D969821284A0BB20005C1BD /* ir.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = ir.bmp; sourceTree = "<group>"; };
121+
9D969822284A0BB20005C1BD /* uv.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = uv.bmp; sourceTree = "<group>"; };
122+
9D969823284A0BB20005C1BD /* white.bmp */ = {isa = PBXFileReference; lastKnownFileType = image.bmp; path = white.bmp; sourceTree = "<group>"; };
102123
9D9F7DB225D56E9B0091C675 /* LCID+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LCID+Extensions.swift"; sourceTree = "<group>"; };
103124
9D9F7DB625D573620091C675 /* GetValuesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetValuesViewController.swift; sourceTree = "<group>"; };
125+
9DA9A40F283693DC0063B00E /* layer.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = layer.json; sourceTree = "<group>"; };
126+
9DA9A412283780450063B00E /* CustomUIModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomUIModels.swift; sourceTree = "<group>"; };
104127
9DC45D2F25D692AC0077AE4A /* DocReaderFrame+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DocReaderFrame+Extensions.swift"; sourceTree = "<group>"; };
105128
9DF08E5025D3C9C700880F7E /* SettingsActionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsActionCell.swift; sourceTree = "<group>"; };
106129
9DF08E5125D3C9C700880F7E /* SettingsActionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsActionCell.xib; sourceTree = "<group>"; };
@@ -160,6 +183,9 @@
160183
9D00FDDA25D3C68A00D6FEF1 /* Resources */ = {
161184
isa = PBXGroup;
162185
children = (
186+
9D969821284A0BB20005C1BD /* ir.bmp */,
187+
9D969822284A0BB20005C1BD /* uv.bmp */,
188+
9D969823284A0BB20005C1BD /* white.bmp */,
163189
9D33E2A525CA940700FF9561 /* Main.storyboard */,
164190
9D33E2A825CA940700FF9561 /* Assets.xcassets */,
165191
9D33E2AA25CA940700FF9561 /* LaunchScreen.storyboard */,
@@ -196,6 +222,7 @@
196222
9D33E29F25CA940700FF9561 /* AppDelegate.swift */,
197223
9D33E2A325CA940700FF9561 /* MainViewController.swift */,
198224
86805409275A3DB00036B3AF /* DocumentReaderService.swift */,
225+
9DA9A40F283693DC0063B00E /* layer.json */,
199226
8673192B27EAFE0600B754DF /* OnlineProcessing */,
200227
9D33E2AD25CA940700FF9561 /* Info.plist */,
201228
9D33E2C925CA9FE400FF9561 /* DocumentReader-Swift.entitlements */,
@@ -258,6 +285,7 @@
258285
9D83E71425D41A3E009DE46F /* Shared */ = {
259286
isa = PBXGroup;
260287
children = (
288+
9DA9A412283780450063B00E /* CustomUIModels.swift */,
261289
9D6D108225D29738001E9158 /* UserSettings.swift */,
262290
9D6D108625D29A4E001E9158 /* Types.swift */,
263291
9D83E71025D4191F009DE46F /* Constants.swift */,
@@ -294,6 +322,7 @@
294322
9D33E29925CA940700FF9561 /* Frameworks */,
295323
9D33E29A25CA940700FF9561 /* Resources */,
296324
F4656F587113E0C8790E21B6 /* [CP] Embed Pods Frameworks */,
325+
9DA9A40C283692830063B00E /* Embed Frameworks */,
297326
);
298327
buildRules = (
299328
);
@@ -342,14 +371,18 @@
342371
isa = PBXResourcesBuildPhase;
343372
buildActionMask = 2147483647;
344373
files = (
374+
9D969824284A0BB20005C1BD /* ir.bmp in Resources */,
345375
9D658B1525CC02F700DDB739 /* ImageCell.xib in Resources */,
346376
9D33E2CF25CAA12200FF9561 /* CertificatesPA.bundle in Resources */,
377+
9DA9A410283693DC0063B00E /* layer.json in Resources */,
347378
9D33E2AC25CA940700FF9561 /* LaunchScreen.storyboard in Resources */,
348379
9D33E2A925CA940700FF9561 /* Assets.xcassets in Resources */,
349380
9D33E2A725CA940700FF9561 /* Main.storyboard in Resources */,
381+
9D969826284A0BB20005C1BD /* white.bmp in Resources */,
350382
9D33E2CE25CAA12200FF9561 /* Certificates.bundle in Resources */,
351383
9DF08E5325D3C9C700880F7E /* SettingsActionCell.xib in Resources */,
352384
9D33E2C525CA9EF500FF9561 /* regula.license in Resources */,
385+
9D969825284A0BB20005C1BD /* uv.bmp in Resources */,
353386
9D658B0F25CC000E00DDB739 /* TextCell.xib in Resources */,
354387
9D9560B825D286D100C0673F /* SettingsSwitchCell.xib in Resources */,
355388
9D33E2D025CAA12200FF9561 /* CertificatesTA.bundle in Resources */,
@@ -422,6 +455,7 @@
422455
9D658B0725CBF3EE00DDB739 /* ResultType+Extensions.swift in Sources */,
423456
9DFBD7DA25E6689900428089 /* RFIDAccessControlProcedureType+Extensions.swift in Sources */,
424457
9D9F7DB725D573620091C675 /* GetValuesViewController.swift in Sources */,
458+
9DA9A413283780450063B00E /* CustomUIModels.swift in Sources */,
425459
8640EC3226F9C35700C8FF4F /* MRZFormat+Extensions.swift in Sources */,
426460
9D33E2A425CA940700FF9561 /* MainViewController.swift in Sources */,
427461
9D053B6F25CD6D770014EE23 /* FieldType+Extensions.swift in Sources */,
@@ -589,6 +623,10 @@
589623
CODE_SIGN_ENTITLEMENTS = "DocumentReader-Swift/DocumentReader-Swift.entitlements";
590624
CODE_SIGN_STYLE = Automatic;
591625
DEVELOPMENT_TEAM = H6WR54S268;
626+
FRAMEWORK_SEARCH_PATHS = (
627+
"$(inherited)",
628+
"$(PROJECT_DIR)/DocumentReader-Swift",
629+
);
592630
INFOPLIST_FILE = "DocumentReader-Swift/Info.plist";
593631
LD_RUNPATH_SEARCH_PATHS = (
594632
"$(inherited)",
@@ -610,6 +648,10 @@
610648
CODE_SIGN_ENTITLEMENTS = "DocumentReader-Swift/DocumentReader-Swift.entitlements";
611649
CODE_SIGN_STYLE = Automatic;
612650
DEVELOPMENT_TEAM = H6WR54S268;
651+
FRAMEWORK_SEARCH_PATHS = (
652+
"$(inherited)",
653+
"$(PROJECT_DIR)/DocumentReader-Swift",
654+
);
613655
INFOPLIST_FILE = "DocumentReader-Swift/Info.plist";
614656
LD_RUNPATH_SEARCH_PATHS = (
615657
"$(inherited)",

Samples/Advanced/DocumentReader-Swift/DocumentReader-Swift/MainViewController.swift

Lines changed: 159 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,41 @@ class MainViewController: UIViewController {
2424
private var sectionsData: [CustomizationSection] = []
2525
private var pickerImages: [UIImage] = []
2626

27+
var isCustomUILayerEnabled: Bool = false
28+
lazy var animationTimer = Timer.scheduledTimer(timeInterval: 1.0/60, target: self, selector: #selector(fireTimer), userInfo: nil, repeats: true)
29+
30+
// JSON string for custom UI layer
31+
let customLayerJsonString =
32+
"""
33+
{
34+
"objects": [
35+
{
36+
"label": {
37+
"text": "Searching document...",
38+
"fontStyle": "normal",
39+
"fontColor": "#FF444444",
40+
"fontSize": 24,
41+
"alignment": "center",
42+
"background": "#BBDDDDDD",
43+
"borderRadius": 10,
44+
"padding": {
45+
"start": 20,
46+
"end": 20,
47+
"top": 20,
48+
"bottom": 20
49+
},
50+
"position": {
51+
"v": 1.0
52+
},
53+
"margin": {
54+
"start": 24,
55+
"end": 24
56+
}
57+
}
58+
}]
59+
}
60+
"""
61+
2762
override func viewDidLoad() {
2863
super.viewDidLoad()
2964

@@ -90,7 +125,12 @@ class MainViewController: UIViewController {
90125
defaultScanner.resetFunctionality = false
91126
let stillImage = CustomizationItem("Gallery (recognizeImages)")
92127
stillImage.actionType = .gallery
93-
let defaultSection = CustomizationSection("Default", [defaultScanner, stillImage])
128+
let recognizeImageInput = CustomizationItem("Recognize images with light type") { [weak self] in
129+
guard let self = self else { return }
130+
self.recognizeImagesWithImageInput()
131+
}
132+
recognizeImageInput.actionType = .custom
133+
let defaultSection = CustomizationSection("Default", [defaultScanner, stillImage, recognizeImageInput])
94134
sectionsData.append(defaultSection)
95135

96136
// 2. Custom modes
@@ -110,8 +150,8 @@ class MainViewController: UIViewController {
110150
}
111151
manualMultipageMode.resetFunctionality = false
112152
manualMultipageMode.actionType = .custom
113-
let childModeSection = CustomizationSection("Custom", [childModeScanner, manualMultipageMode, onlineProcessing])
114-
sectionsData.append(childModeSection)
153+
let customModedSection = CustomizationSection("Custom", [childModeScanner, manualMultipageMode, onlineProcessing])
154+
sectionsData.append(customModedSection)
115155

116156
// 3. Custom camera frame
117157
let customBorderWidth = CustomizationItem("Custom border width") { () -> (Void) in
@@ -234,7 +274,17 @@ class MainViewController: UIViewController {
234274
DocReader.shared.customization.customStatusPositionMultiplier = 0.5
235275
}
236276

237-
let freeCustomStatusItems = [freeCustomTextAndPostion]
277+
let customUILayerModeStatic = CustomizationItem("Custom Status & Image") { [weak self] in
278+
guard let self = self else { return }
279+
self.setupCustomUIFromFile()
280+
}
281+
let customUILayerModeAnimated = CustomizationItem("Custom Status Animated") { [weak self] in
282+
guard let self = self else { return }
283+
self.isCustomUILayerEnabled = true
284+
self.animationTimer.fire()
285+
}
286+
287+
let freeCustomStatusItems = [freeCustomTextAndPostion, customUILayerModeStatic, customUILayerModeAnimated]
238288
let freeCustomStatusSection = CustomizationSection("Free custom status", freeCustomStatusItems)
239289
sectionsData.append(freeCustomStatusSection)
240290

@@ -303,7 +353,7 @@ class MainViewController: UIViewController {
303353
case .cancel:
304354
print("Cancelled by user")
305355
DocReader.shared.functionality.manualMultipageMode = false
306-
case .complete:
356+
case .complete, .processTimeout:
307357
guard let results = result else {
308358
return
309359
}
@@ -328,6 +378,42 @@ class MainViewController: UIViewController {
328378
}
329379
}
330380

381+
private func recognizeImagesWithImageInput() {
382+
let whiteImage = UIImage(named: "white.bmp")
383+
let uvImage = UIImage(named: "uv.bmp")
384+
let irImage = UIImage(named: "ir.bmp")
385+
386+
let whiteInput = DocReader.ImageInput(image: whiteImage!, light: .white, pageIndex: 0)
387+
let uvInput = DocReader.ImageInput(image: uvImage!, light: .UV, pageIndex: 0)
388+
let irInput = DocReader.ImageInput(image: irImage!, light: .infrared, pageIndex: 0)
389+
390+
DocReader.shared.recognizeImages(with: [whiteInput, irInput, uvInput]) { action, results, error in
391+
switch action {
392+
case .cancel:
393+
self.stopCustomUIChanges()
394+
print("Cancelled by user")
395+
case .complete, .processTimeout:
396+
self.stopCustomUIChanges()
397+
guard let opticalResults = results else {
398+
return
399+
}
400+
self.showResultScreen(opticalResults)
401+
case .error:
402+
self.stopCustomUIChanges()
403+
print("Error")
404+
guard let error = error else { return }
405+
print("Error string: \(error)")
406+
case .process:
407+
guard let result = results else { return }
408+
print("Scaning not finished. Result: \(result)")
409+
case .morePagesAvailable:
410+
print("This status couldn't be here, it uses for -recognizeImage function")
411+
default:
412+
break
413+
}
414+
}
415+
}
416+
331417
private func showAsChildViewController() {
332418
let mainStoryboard = UIStoryboard(name: kMainStoryboardId, bundle: nil)
333419
guard let childViewController = mainStoryboard.instantiateViewController(withIdentifier: kChildViewController) as? ChildViewController else {
@@ -448,10 +534,13 @@ class MainViewController: UIViewController {
448534
private func showCameraViewController() {
449535
DocReader.shared.showScanner(self) { [weak self] (action, result, error) in
450536
guard let self = self else { return }
537+
451538
switch action {
452539
case .cancel:
540+
self.stopCustomUIChanges()
453541
print("Cancelled by user")
454-
case .complete:
542+
case .complete, .processTimeout:
543+
self.stopCustomUIChanges()
455544
guard let opticalResults = result else {
456545
return
457546
}
@@ -461,6 +550,7 @@ class MainViewController: UIViewController {
461550
self.showResultScreen(opticalResults)
462551
}
463552
case .error:
553+
self.stopCustomUIChanges()
464554
print("Error")
465555
guard let error = error else { return }
466556
print("Error string: \(error)")
@@ -636,6 +726,69 @@ class MainViewController: UIViewController {
636726

637727
return paCertificates
638728
}
729+
730+
private func setupCustomUIFromFile() {
731+
if let path = Bundle.main.path(forResource: "layer", ofType: "json") {
732+
do {
733+
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
734+
let jsonDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: AnyObject]
735+
DocReader.shared.customization.customUILayerJSON = jsonDict
736+
} catch {
737+
738+
}
739+
}
740+
}
741+
742+
@objc func fireTimer() {
743+
/*
744+
This example with Timer shows how you can change different properties of elements at runtime,
745+
such as text, position, color etc. Little bit overhead, but it show how it can changed over time.
746+
Also you can extend model with you properties such like ID, and access by it in runtime.
747+
If you don't need that kind of flexibility, you can just use a static JSON file.
748+
*/
749+
guard isCustomUILayerEnabled else {
750+
return
751+
}
752+
753+
guard let jsonData = customLayerJsonString.data(using: .utf8) else {
754+
return
755+
}
756+
757+
guard var model = try? JSONDecoder().decode(CustomUILayerModel.self, from: jsonData) else {
758+
return
759+
}
760+
761+
guard var object = model.objects.first else {
762+
return
763+
}
764+
765+
let date = Date()
766+
let dateFormatter = DateFormatter()
767+
dateFormatter.dateFormat = "HH:mm:ss"
768+
object.label.text = "Custom label that showing current time: \(dateFormatter.string(from: date))"
769+
770+
let ct = CACurrentMediaTime()
771+
object.label.position.v = 1.0 + sin(ct) * 0.5 // Move vertically from 0.5 to 1.5
772+
773+
let encoder = JSONEncoder()
774+
encoder.outputFormatting = .prettyPrinted
775+
776+
model.objects = [object]
777+
778+
do {
779+
let data = try encoder.encode(model)
780+
if let jsonDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
781+
DocReader.shared.customization.customUILayerJSON = jsonDict
782+
}
783+
} catch {
784+
785+
}
786+
}
787+
788+
private func stopCustomUIChanges() {
789+
isCustomUILayerEnabled = false
790+
DocReader.shared.customization.customUILayerJSON = nil
791+
}
639792
}
640793

641794
// MARK: - UITableViewDataSource & UITableViewDelegate
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)