User Level ========== The User Level regroups the features that have an impact on the user experience. The Socket barcode scanners provide ways to notify the user when the barcode read is correct or incorrect without the need for the user to check the screen of the host. The scanner has 3 types of feedback: sound, LED and vibrate. For example, depending on the environment, you may want to turn off the sound and use only the vibration. Here are some examples on how to use these feedback mechanisms. Turning off the Sound ^^^^^^^^^^^^^^^^^^^^^ Turning off the good read sound is a simple 2 step process. Since this setting is persistent on the scanner, it is best to first read this setting when the scanner connects and depending on its state, either change it or just continue on. Let's imagine we would like to offer to the user a switch button in the UI to turn on or off the beep when scanning a barcode. The ``didNotifyArrivalForDevice`` delegate is used to request the actual state of the scanner local decode action so the switch to configure this setting could be positioned accordingly to the actual state of the scanner decode action. The code might look like this:: -(void)didNotifyArrivalForDevice:(SKTCaptureHelperDevice*) device withResult:(SKTResult) result{ NSLog(@"Receive device arrival for %@", device.friendlyName); dispatch_async(dispatch_get_main_queue(), ^{ _statusLabel.text = device.friendlyName; }); // ask for the device Battery Level [device getBatteryLevelWithCompletionHandler:^(SKTResult result, NSInteger levelInPercentage) { [self displayBatteryLevel: levelInPercentage]; }]; [device getDecodeActionWithCompletionHandler:^(SKTResult result, SKTCaptureLocalDecodeAction decodeAction) { if (result == SKTCaptureE_NOERROR){ device.localDecodeAction = decodeAction; dispatch_async(dispatch_get_main_queue(), ^{ if((decodeAction&SKTCaptureLocalDecodeActionBeep) == SKTCaptureLocalDecodeActionBeep){ [[self beepSwitch]setOn: TRUE]; } else { [[self beepSwitch]setOn: FALSE]; } [[self beepSwitch]setEnabled:TRUE]; }); } }]; _lastDeviceConnected = device; } .. note:: The completion handler of ``getDecodeActionWithCompletionHandler`` has the code refreshing the UI in the main dispatch queue using the ``dispatch_async(dispatch_get_main_queue(), ^{...});`` function to have the block code running in the context of the main thread. Then the handler of the ``beepSwitch`` switch is in charge of turning off or on the beep when the scanner reads a barcode and the code could look like this:: - (IBAction)didChangeBeepSwitch:(id)sender { SKTCaptureLocalDecodeAction decodeAction = _lastDeviceConnected.localDecodeAction; if( [[self beepSwitch]isOn]){ decodeAction = decodeAction | SKTCaptureLocalDecodeActionBeep; } else{ decodeAction = decodeAction& ~SKTCaptureLocalDecodeActionBeep; } [_lastDeviceConnected setDecodeAction:decodeAction completionHandler:^(SKTResult result) { NSLog(@"Setting the Decode Action returned: %ld", (long)result); if (result == SKTCaptureE_NOERROR){ _lastDeviceConnected.localDecodeAction = decodeAction; } else { dispatch_async(dispatch_get_main_queue(), ^{ [[self beepSwitch]setOn:![[self beepSwitch]isOn]]; }); } }]; } .. note:: This code update the UI controls directly in the completion handler and that is possible only because the code updating the UI is in the block that has been dispatched on the main queue: ``dispatch_async(dispatch_get_main_queue(), ^{...});`` The current state of the device decode action is saved by adding a computed property ``localDecodeAction`` in an Category class for ``CaptureHelperDevice``. Since a Objective-C Category class cannot declare properties, the original CaptureHelperDevice and CaptureHelper classes both provide a `extensionProperties` member which is a dictionary that can be used to implement this kind of feature. So in this particular example our extension class could look like this:: #import "SktCaptureHelper.h" @interface SKTCaptureHelperDevice (Persistence) @property (getter=getLocalDecodeAction, setter=setLocalDecodeAction:)SKTCaptureLocalDecodeAction localDecodeAction; @end and its implementation could be something looking like this:: #import "SKTCaptureHelperDevice+Persistence.h" @implementation SKTCaptureHelperDevice(Persistence) -(void)setLocalDecodeAction:(SKTCaptureLocalDecodeAction)decodeAction{ if(self->_extensionProperties == nil) { self->_extensionProperties = [NSMutableDictionary new]; } NSNumber *value = [NSNumber numberWithLong:(long)decodeAction]; [self->_extensionProperties setValue:value forKey:@"decodeAction"]; } -(SKTCaptureLocalDecodeAction)getLocalDecodeAction{ if(self->_extensionProperties != nil){ NSNumber* value = [self->_extensionProperties valueForKey:@"decodeAction"]; if(value != nil){ return (SKTCaptureLocalDecodeAction)value.longValue; } } return SKTCaptureLocalDecodeActionNone; } @end Here the decode action is stored in the `extensionProperties` of the CaptureHelperDevice class. That's how we can keep the actual value of the decode action by adding this computed property: `decodeAction`. Locate the Scanner ^^^^^^^^^^^^^^^^^^ ''Locate the Scanner'' might be a nice feature to help the user identify which scanner is theirs in a situation where more than one scanner is in the area. This feature could be implemented with a repeated action of sending a Data Confirmation to the scanner to cause the scanner to beep or flash or vibrate. Here is code example of a command that would need to be in a timer handler:: if(_lastDeviceConnected != nil){ [_lastDeviceConnected setDataConfirmationWithLed:SKTCaptureDataConfirmationLedGreen withBeep:SKTCaptureDataConfirmationBeepGood withRumble:SKTCaptureDataConfirmationRumbleGood completionHandler:^(SKTResult result) { NSLog(@"setDataConfirmation returns: %ld",(long)result); }]; } The ``_lastDeviceConnected`` in this code is set to a ``CaptureHelperDevice`` instance in the ``didNotifyArrivalForDevice`` delegate to reference the last connected device. .. note:: Triggering the scanner remotely shows the scanner aiming light which could also help to find or identify the connected scanner. This use requires caution though because it might scan a barcode. .. _wrongbarcodeindicationobjclabel: Wrong Barcode Indication ^^^^^^^^^^^^^^^^^^^^^^^^ Wrong barcode indication can be useful when a user scans a barcode but that barcode was not expected at that moment in the application or is not the expected symbology or format. Of course the application UI could display a user friendly error, but maybe the user is scanning a bunch of barcodes without looking at the screen. So sending back to the user an indication that something is wrong after having scanning a barcode might be useful. Here is an example of code that can be invoked when such a condition occurs in the application:: [device setDataConfirmationWithLed:SKTCaptureDataConfirmationLedRed withBeep:SKTCaptureDataConfirmationBeepBad withRumble:SKTCaptureDataConfirmationRumbleBad completionHandler:^(SKTResult result) { NSLog(@"setDataConfirmation returns: %ld",(long)result); }]; The ``device`` in this code is a ``CaptureHelperDevice`` object instance. .. _disablingscannertriggerobjclabel: Disabling the Scanner Trigger Button ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Upon detection of a wrong barcode and requiring the user to acknowledge an eventual informational message on the host screen, the Scanner Trigger button can be disabled. Here is a sample code for disabling the Scanner Trigger button:: SKTCaptureTrigger trigger = SKTCaptureTriggerDisable; [_lastDeviceConnected setTrigger: trigger completionHandler:^(SKTResult result) { NSLog(@"The trigger is %ld with result %ld",(long)trigger,(long)result); }]; And to re-enable the button:: SKTCaptureTrigger trigger = SKTCaptureTriggerEnable; [_lastDeviceConnected setTrigger: trigger completionHandler:^(SKTResult result) { NSLog(@"The trigger is %ld with result %ld",(long)trigger,(long)result); }]; The _lastDeviceConnected in this code is a ``CaptureHelperDevice`` object instance. .. note:: The Scanner can be configured with a Data Confirmation Mode set to either the application or to Capture. In both cases, the trigger is disabled until the data is confirmed or a timeout has elapsed. Please refer to the Application Level :ref:`Data Confirmation from the App`.