Connect to our products with Companion app¶
First initialize Capture Helper. Please refer to Capture Helper initialization.
Then install our Socket Mobile Companion app which takes care of the discovery and the selection of the reader to connect to.
In terms of code, you just need to implement the delegate methods to be notified when a device is connected or disconnected.
func didNotifyArrivalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) {
print("didNotifyArrivalForDevice: \(String(describing: device.deviceInfo.name))")
self.myDeviceConnected = device
}
func didNotifyRemovalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) {
print("didNotifyRemovalForDevice: \(String(describing: device.deviceInfo.name))")
self.myDeviceConnected = nil
}
-(void)didNotifyArrivalForDevice:(SKTCaptureHelperDevice *)device withResult:(SKTResult)result {
[self updateStatusFromDevices:[_capture getDevicesList]];
}
-(void)didNotifyRemovalForDevice:(SKTCaptureHelperDevice *)device withResult:(SKTResult)result {
[self updateStatusFromDevices:[_capture getDevicesList]];
}
Additional Context¶
Note
This code shown above updates the UI from the didNotifyArrivalForDevice
and from the didNotifyRemovalForDevice
which requires it to be executed in
the main thread. This could be accomplished in different ways, but Capture
Helper provides a property to simplify this process as shown here:
capture.dispatchQueue = DispatchQueue.main
This is usually done before opening Capture. The same logic applies for each
device received in the didNotifyArrivalForDevice
if the callback of a
device function needs to update the UI.
Note
For a combo device like the S370 which has 2 devices, there will be two didNotifyArrivalForDevice
and two didNotifyRemovalForDevice
notifications.
The following code shows how you can distinghuish and handle them:
func didNotifyArrivalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) {
print("didNotifyArrivalForDevice: \(String(describing: device.deviceInfo.name))")
if device.deviceInfo.deviceType == .NFCS370 {
// handle the NFC reader of the S370
} else if device.deviceInfo.deviceType == .scannerS370 {
// handle the Barcode scanner of the S370
}
}
-(void)didNotifyArrivalForDevice:(SKTCaptureHelperDevice *)device withResult:(SKTResult)result {
NSLog(@"Device arrival for %@", device.deviceInfo.name);
if device.deviceInfo.deviceType == SKTCaptureDeviceTypeNFCS370 {
// handle the NFC reader of the S370
} else if device.deviceInfo.deviceType == SKTCaptureDeviceTypeScannerS370 {
// handle the Barcode scanner of the S370
}
}
You can also check if a device is barcode reader or a NFC reader when you get the didNotifyArrivalForDevice
:
func didNotifyArrivalForDevice(_ device: CaptureHelperDevice, withResult result: SKTResult) {
print("didNotifyArrivalForDevice: \(String(describing: device.deviceInfo.name))")
if device.isNFCReader {
// handle the NFC reader of the S370 or another NFC reader like a S550
} else if device.isBarcodeReader {
// handle the Barcode scanner of the S370 or another barcode scanner like a S320 or S740
}
}
-(void)didNotifyArrivalForDevice:(SKTCaptureHelperDevice *)device withResult:(SKTResult)result {
NSLog(@"Device arrival for %@", device.friendlyName);
if ([device isNFCReader]) {
// handle the NFC reader of the S370 or another NFC reader like a S550
} else if ([device isBarcodeReader]) {
// handle the Barcode scanner of the S370 or another barcode scanner like a S320 or S740
}
}