Skip to content

Instantly share code, notes, and snippets.

@xslim
Created April 18, 2016 18:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xslim/1d9392fb8a765af94480d7bddb952f29 to your computer and use it in GitHub Desktop.
Save xslim/1d9392fb8a765af94480d7bddb952f29 to your computer and use it in GitHub Desktop.
Barcode scanning on E315 with AdyenPOS lib
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(barcodeReceived:)
name:ADYNotificationBarcodeReceived
object:nil];
// Optional - button to trigger soft scan
UIButton *barcodeBtn = [[UIButton alloc] init];
[barcodeBtn setTitle:@"Barcode" forState:UIControlStateNormal];
[barcodeBtn addTarget:self action:@selector(startBarcodeScan:) forControlEvents:UIControlEventTouchDown];
[barcodeBtn addTarget:self action:@selector(stopBarcodeScan:) forControlEvents:UIControlEventTouchUpInside];
[barcodeBtn sizeToFit];
}
- (void)barcodeReceived:(NSNotification *)notification {
if (!notification.object) return;
NSString *barcode = notification.object;
NSString *symbology = notification.userInfo[@"symbology"] ? notification.userInfo[@"symbology"] : @"";
ADYBarcodeType barcodeType = [notification.userInfo[@"type"] integerValue];
NSLog(@"Barcode %@ (%i)", symbology, (int)barcodeType);
}
// Optional - Soft scan
- (IBAction)startBarcodeScan:(id)sender {
ADYDeviceRegistry *deviceRegistry = [Adyen sharedInstance].deviceRegistry;
if (deviceRegistry.devices.count == 0) return;
ADYDevice *device = deviceRegistry.devices[0];
[device startBarcodeScan];
}
- (IBAction)stopBarcodeScan:(id)sender {
ADYDeviceRegistry *deviceRegistry = [Adyen sharedInstance].deviceRegistry;
if (deviceRegistry.devices.count == 0) return;
ADYDevice *device = deviceRegistry.devices[0];
[device stopBarcodeScan];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment