|
1 | | -# CaptureSDK Version 2.0.16 - Swift Package Manager |
| 1 | +# CaptureSDK Version 2.0.29 - Swift Package Manager |
2 | 2 |
|
3 | 3 | Socket Mobile is a leading innovator of data capture and delivery solutions for enhanced productivity. |
4 | 4 |
|
@@ -124,123 +124,14 @@ Once `CaptureSDK` is open, then the device arrival notification can occurs as so |
124 | 124 |
|
125 | 125 | The decoded data coming from the scanner can be retrieved by overriding the `onDecodedData` delegate. |
126 | 126 |
|
127 | | -### 4. Summary for integrating `CaptureSDK` in a Xcode project |
128 | | - |
129 | | -Example of ViewController.m for SingleEntry app: |
130 | | - |
131 | | -```swift |
132 | | -import UIKit |
133 | | -import CaptureSDK |
134 | | - |
135 | | -class MasterViewController: |
136 | | - UITableViewController, |
137 | | - CaptureHelperDevicePresenceDelegate, |
138 | | - CaptureHelperDeviceManagerPresenceDelegate, |
139 | | - CaptureHelperDeviceDecodedDataDelegate, |
140 | | - CaptureHelperErrorDelegate, |
141 | | - CaptureHelperDevicePowerDelegate { |
142 | | - |
143 | | - |
144 | | - // Capture Helper shareInstance allows to share |
145 | | - // the same instance of Capture Helper with the |
146 | | - // entire application. That static property can |
147 | | - // be used in any views but it is recommended |
148 | | - // to open only once Capture Helper (in the main |
149 | | - // view controller) and pushDelegate, popDelegate |
150 | | - // each time a new view requiring scanning capability |
151 | | - // is loaded or unloaded respectively. |
152 | | - var captureHelper = CaptureHelper.sharedInstance |
153 | | - |
154 | | - override func viewDidLoad() { |
155 | | - super.viewDidLoad() |
156 | | - // Do any additional setup after loading the view, typically from a nib. |
157 | | - // fill out the App Info with the Bundle ID which should start by the |
158 | | - // platform on which the application is running and followed with the |
159 | | - // case sensitive application Bundle ID, |
160 | | - // with the Socket Mobile Portal developer ID |
161 | | - // and with the Application Key generated from the Socket Mobile Developer |
162 | | - // portal |
163 | | - let AppInfo = SKTAppInfo() |
164 | | - AppInfo.appKey = "MC0CFQD1tdTpaABkppmG+iP3dB9kolYVtwIUY8c3UmEfaPoTI3AxbPOTpNgw+fo=" |
165 | | - AppInfo.appID = "ios:com.socketmobile.SingleEntrySwift" |
166 | | - AppInfo.developerID = "bb57d8e1-f911-47ba-b510-693be162686a" |
167 | | - |
168 | | - // there is a stack of delegates the last push is the |
169 | | - // delegate active, when a new view requiring notifications from the |
170 | | - // scanner, then push its delegate and pop its delegate when the |
171 | | - // view is done |
172 | | - captureHelper.pushDelegate(self) |
173 | | - |
174 | | - // to make all the delegates able to update the UI without the app |
175 | | - // having to dispatch the UI update code, set the dispatchQueue |
176 | | - // property to the DispatchQueue.main |
177 | | - captureHelper.dispatchQueue = DispatchQueue.main |
178 | | - |
179 | | - // open Capture Helper only once in the application |
180 | | - captureHelper.openWithAppInfo(AppInfo, withCompletionHandler: { (_ result: SKTResult) in |
181 | | - print("Result of Capture initialization: \(result.rawValue)") |
182 | | - }) |
183 | | - } |
184 | | -} |
185 | | -``` |
186 | | - |
187 | | -`CaptureHelper` makes the application aware of a new device connection by invoking the `onDeviceArrival` of the protocol and, in the same way when a device disconnects, the `onDeviceRemoval` is invoked. A `CaptureHelper` device instance representing the device that is connected can be used to retrieve or set a device property. |
188 | | - |
189 | | -Example of the view controller being aware of the scanner: |
190 | | - |
191 | | -```swift |
192 | | -func didNotifyArrivalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) { |
193 | | - print("Main view device arrival:\(device.deviceInfo.name!)") |
194 | | -} |
195 | | - |
196 | | -func didNotifyRemovalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) { |
197 | | - print("Main view device removal:\(device.deviceInfo.name!)") |
198 | | -} |
199 | | -``` |
200 | | - |
201 | | -For a combo device like the S370 which has 2 devices, there will be two ``didNotifyArrivalForDevice`` and two ``didNotifyRemovalForDevice`` notifications. |
202 | | - |
203 | | -The following code shows how you can distinghuish and handle them: |
204 | | - |
205 | | -```swift |
206 | | -func didNotifyArrivalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) { |
207 | | - print("didNotifyArrivalForDevice: \(String(describing: device.deviceInfo.name))") |
208 | | - if device.deviceInfo.deviceType == .NFCS370 { |
209 | | - // handle the NFC reader of the S370 |
210 | | - } else if device.deviceInfo.deviceType == .scannerS370 { |
211 | | - // handle the Barcode scanner of the S370 |
212 | | - } |
213 | | -} |
214 | | -``` |
215 | | - |
216 | | -If the scanner triggers a scan, the decoded data can be retrieve in the protocol function `onDecodedData`. |
217 | | - |
218 | | -Example of retrieving the decoded data received by a scanner: |
219 | | - |
220 | | -```swift |
221 | | -func didReceiveDecodedData(_ decodedData: SKTCaptureDecodedData?, fromDevice device: CaptureHelperDevice, withResult result: SKTResult) { |
222 | | - if result == SKTCaptureErrors.E_NOERROR { |
223 | | - let rawData = decodedData?.decodedData |
224 | | - let rawDataSize = rawData?.count |
225 | | - print("Size: \(String(describing: rawDataSize))") |
226 | | - print("data: \(String(describing: decodedData?.decodedData))") |
227 | | - let string = decodedData?.stringFromDecodedData()! |
228 | | - print("Decoded Data \(String(describing: string))") |
229 | | - } |
230 | | -} |
231 | | -``` |
232 | | - |
233 | | -The application can retrieve or modify the device properties by calling the various `CaptureHelperDevice` get/set methods. By example there is a method to retrieve the device friendly name: `getFriendlyNameWithCompletionHandler`. The call is asynchronous and will return immediately. The final result and the friendly name can be retrieved in the |
234 | | -completion handler function block. |
235 | | - |
236 | 127 | **IMPORTANT**: |
237 | 128 | If a property is not accessible through the available `CaptureHelper` methods, it is very easy to add new ones, by creating a `CaptureHelper` **extension** class and copy and paste a similar get/set method and change the property settings inside the new method. |
238 | 129 |
|
239 | 130 | Creating a `CaptureHelper` extension allows to avoid an overwrite of a modified version of `CaptureHelper` when updating to a more recent `CaptureSDK` CocoaPods. |
240 | 131 |
|
241 | | -## Sample code |
| 132 | +### 4. Sample code |
242 | 133 |
|
243 | | -Sample code can be found in [GitHub / SocketMobile](https://github.com/SocketMobile "Socket Mobile Samples") |
| 134 | +Try out our sample [our Single Entry app on Github SocketMobile](https://github.com/SocketMobile/capturesingleentryswift-ios) |
244 | 135 |
|
245 | 136 | ## SocketCam C820 and C860 |
246 | 137 |
|
|
0 commit comments