Created
April 18, 2016 18:43
-
-
Save xslim/1d9392fb8a765af94480d7bddb952f29 to your computer and use it in GitHub Desktop.
Barcode scanning on E315 with AdyenPOS lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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