We’ve been working with a client on a nifty little application that compliments their desktop workhorse. There are a couple cool things about this application. One it makes use of RESTful services to connect with their legacy system to collect and manipulate data, but that isn’t the coolest aspect of the project. The coolest part is how we collect user input.
Barcodes
Our client makes heavy use of barcodes in their application. To that end they decided to make use of KoamTac 300i and LineaPro Bluetooth barcode scanners. These two scanners include SDK’s so you can get tighter integration with the hardware. It makes total sense to get tighter integration because we don’t have any UITextView’s to collect input from a standard HID device. If you’re using a bluetooth barcode scanner and have a UITextView to collect input it’s fairly easy to use any scanner. It works just like a keyboard, but what about apps like this that don’t have a place to collect data? That’s where the SDK’s come in handy.
Detecting External Hardware
Since we have to integrate with multiple scanners we have to decide at runtime which scanner is being used. Using the SDK’s we could take a stab in the dark at initializing each one in turn and the one that succeeds to initialize is the winner. Not such a great way determine the one to use, but it would work.
What if there was a way to determine you had connected external devices without using a third party SDK? There is.
Using the External Accessory Framework you can do just that.
Here’s a little snippet of code you can use to get back a list of external devices connected to your iOS device. That’s all there is to it. The output produced from that small bit of code appears below.
Make sure you #import <ExternalAccessory/ExternalAccessory.h>
[code lang=”objc”]
– (void)_getAttachedDevices;
{
EAAccessoryManager* accessoryManager = [
EAAccessoryManager sharedAccessoryManager];
if (accessoryManager)
{
NSArray* connectedAccessories =
[accessoryManager connectedAccessories];
NSLog(@"ConnectedAccessories = %@", connectedAccessories);
}
}
[/code]
All this little piece of code does is get the shared Accessory Manager, EAAccessoryManager (man, I hate that name), and asks for connected accessories. Simple! The NSLog() call simply dumps out an instance of EAAccessory which describes the connected accessory. In this case we’re connected to a LINEA Pro scanner.
ConnectedAccessories = (
"<EAAccessory: 0x1f7810>
{\n connected:YES\n
connectionID:0xd0ff600\n
name: LINEA Pro\n
manufacturer: DATECS\n
modelNumber: XBAMBL\n
serialNumber: MSC140045UN11\n
firmwareRevision: 2.45.0\n
hardwareRevision: 1.0.0\n
protocols: (\n \"com.datecs.linea.pro.msr\",\n \"com.datecs.linea.pro.bar\"\n)\n
delegate: (null)\n}"
)
Need an iOS Developer to help turn your vision into reality? Get in touch, we’re here to help.