forked from ibm-ecm/ibm-autocapture-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageUploadViewController.swift
More file actions
121 lines (96 loc) · 5.02 KB
/
ImageUploadViewController.swift
File metadata and controls
121 lines (96 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// ImageUploadViewController.swift
// IBMDatacapSDKDeskew
//
// Copyright © 2016 IBM Corporation. All rights reserved.
//
import UIKit
struct SampleDatacapConfiguration {
@nonobjc static let url = "<IBM Datacap Server URL>"
@nonobjc static let userName = "<IBM Datacap user name>"
@nonobjc static let userPassword = "<IBM Datacap user password>"
@nonobjc static let stationId = "<IBM Datacap station ID>"
@nonobjc static let stationIndex:Int32 = 0 //Station Index related to that Id
@nonobjc static let applicationName = "<IBM Datacap application>"
@nonobjc static let workflowId = "<Application Workflow id>"
@nonobjc static let workflowIndex:Int32 = 0 //Index related to the selected Application Workflow
@nonobjc static let jobId = "<Workflow Job Id>"
@nonobjc static let jobIndex:Int32 = 0 //Index related to the selected Workflow Job
@nonobjc static let setupDCOName = "<Setup DCO configuration name>"
@nonobjc static let batchTypeId = "<Batch Type Id>"
@nonobjc static let documentTypeId = "<Batch document type Id>"
@nonobjc static let pageTypeId = "<Page Type Id>"
}
class ImageUploadViewController: UIViewController {
var originalImage:UIImage!
var modifiedImage:UIImage!
@IBOutlet weak var statusLabel: UILabel!
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
@IBOutlet weak var activityIndicatorHeightConstraint: NSLayoutConstraint!
var sessionManager:ICPSessionManager!
var status:String {
get { return statusLabel?.text ?? "" }
set { statusLabel?.text = newValue }
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.hidesBarsOnTap = false
self.navigationController?.setToolbarHidden(true, animated: false)
status = "Creating document"
guard let originalImage = originalImage, let modifiedImage = modifiedImage else {
status = "Missing images"
return
}
guard let url = NSURL(string: SampleDatacapConfiguration.url) else {
status = "Invalid URL"
return
}
guard let capture = ICPCapture.instanceWithObjectFactoryType(.NonPersistent) else {
status = "Failed to create Datacap instance"
return
}
guard let objectFactory = capture.objectFactory else {
status = "Failed to create Datacap database"
return
}
guard let service = capture.objectFactory?.datacapServiceWithBaseURL(url) else {
status = "Failed to create service"
return
}
service.station = objectFactory.stationWithStationId(SampleDatacapConfiguration.stationId, andIndex: SampleDatacapConfiguration.stationIndex, andDescription: "")
service.application = objectFactory.applicationWithName(SampleDatacapConfiguration.applicationName)
service.workflow = objectFactory.workflowWithWorkflowId(SampleDatacapConfiguration.workflowId, andIndex: SampleDatacapConfiguration.workflowIndex)
service.job = objectFactory.jobWithJobId(SampleDatacapConfiguration.jobId, andIndex: SampleDatacapConfiguration.jobIndex)
service.setupDCO = objectFactory.setupDCOWithName(SampleDatacapConfiguration.setupDCOName)
let urlCredential = NSURLCredential(user: SampleDatacapConfiguration.userName, password: SampleDatacapConfiguration.userPassword, persistence: .ForSession)
let batchType = objectFactory.batchTypeWithTypeId(SampleDatacapConfiguration.batchTypeId, inDatacapService: service)
let batch = objectFactory.batchWithService(service, type: batchType)
let documentType = objectFactory.documentTypeWithTypeId(SampleDatacapConfiguration.documentTypeId)
let document = objectFactory.documentWithBatch(batch, type: documentType)
let pageType = objectFactory.pageTypeWithTypeId(SampleDatacapConfiguration.pageTypeId)
let page = objectFactory.pageWithDocument(document, type: pageType)
page.modifiedImage = modifiedImage
page.originalImage = originalImage
self.sessionManager = capture.datacapSessionManagerForService(service, withCredential: urlCredential)
self.sessionManager?.uploadBatch(batch, withProgressBlock: self.progressBlock, andCompletion: self.completion)
}
func startAnimation() {
self.activityIndicatorHeightConstraint.constant = 37
self.activityIndicator.startAnimating()
}
func stopAnimation() {
self.activityIndicatorHeightConstraint.constant = 0
self.activityIndicator.stopAnimating()
}
func progressBlock(progress:Float, object:AnyObject?) {
status = "Uploading..."
}
func completion(success:Bool, batch:ICPBatch?, error:NSError?) {
self.activityIndicator.stopAnimating()
if let error = error {
status = "Error on upload: \(error)"
} else {
status = "Image uploaded"
}
}
}