You can use our samples to get a good overview of how to show the barcode scanner in an app: Run the samples.
The Scan User Interface can be presented in various ways. For alternative ways of presenting the scanner (e.g., with a UINavigationController, a UITabViewController, as a subview or in landscape mode), you can also check out the source code and the app of the ExtendedProjectSample that comes with the Scandit SDK.
All code snippets are taken from the source code of the ExtendedProjectSample that comes with the Scandit SDK (DemoViewController.m and OtherExamplesViewController.m).
Objective-C:
self.backgroundButton.hidden = NO;
[self addChildViewController:self.scanditBarcodePicker];
[self.view addSubview:self.scanditBarcodePicker.view];
[self.scanditBarcodePicker didMoveToParentViewController:self];
[self.scanditBarcodePicker.view setTranslatesAutoresizingMaskIntoConstraints:NO];
UIView *pickerView = self.scanditBarcodePicker.view;
NSDictionary *views = NSDictionaryOfVariableBindings(pickerView);
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
id topGuide = self.topLayoutGuide;
views = NSDictionaryOfVariableBindings(pickerView, topGuide);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[topGuide][pickerView(300)]"
options:0
metrics:nil
views:views]];
} else {
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(50)-[pickerView(300)]"
options:0
metrics:nil
views:views]];
}
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[pickerView]|"
options:0
metrics:nil
views:views]];
[self.scanditBarcodePicker startScanning];
Swift:
let picker = SBSBarcodePicker(settings: scanSettings)
picker.scanDelegate = self
addBarcodeResult()
addChildViewController(picker)
picker.view.translatesAutoresizingMaskIntoConstraints = false
overview.addSubview(picker.view)
picker.didMove(toParentViewController: parent)
picker.view.constrainToCenter(of: view, width: 200, height: 400)
overview.isHidden = false
picker.startScanning()
Objective-C:
[self.scanditBarcodePicker.overlayController showToolBar:YES];
[self.scanditBarcodePicker.overlayController setCameraSwitchVisibility:SBSCameraSwitchVisibilityOnTablet];
self.scanditBarcodePicker.scanDelegate = self;
self.scanditBarcodePicker.overlayController.cancelDelegate = self;
self.modalStartAnimationDone = NO;
[self presentViewController:self.scanditBarcodePicker animated:YES completion:^{
if (self.modalBufferedResult != nil) {
[self.scanditBarcodePicker pauseScanning];
[self returnBuffer];
}
self.modalStartAnimationDone = YES;
}];
[self.scanditBarcodePicker startScanning];
Swift:
let picker = SBSBarcodePicker(settings: scanSettings)
picker.overlayController.showToolBar(true)
picker.scanDelegate = self
picker.overlayController.cancelDelegate = self
picker.addChildViewController(barcodeResult)
barcodeResult.view.translatesAutoresizingMaskIntoConstraints = false
picker.view.addSubview(barcodeResult.view)
barcodeResult.view.constrainToEdges(of: picker.view)
barcodeResult.view.isHidden = true
barcodeResult.didMove(toParentViewController: picker)
present(picker, animated: true)
picker.startScanning()
Pushing the SBSBarcodePicker in a Navigation Controller
Objective-C:
SBSBarcodePicker *barcodePicker = [[
SBSBarcodePicker alloc] initWithSettings:settings];
[self.navigationController setNavigationBarHidden:NO animated:NO];
[barcodePicker.overlayController setCameraSwitchVisibility:SBSCameraSwitchVisibilityOnTablet];
[self.navigationController pushViewController:barcodePicker animated:YES];
Swift:
let picker = SBSBarcodePicker(settings: scanSettings)
picker.scanDelegate = self
picker.addChildViewController(barcodeResult)
barcodeResult.view.translatesAutoresizingMaskIntoConstraints = false
picker.view.addSubview(barcodeResult.view)
barcodeResult.view.constrainToEdges(of: picker.view)
barcodeResult.view.isHidden = true
barcodeResult.didMove(toParentViewController: picker)
navigationController?.pushViewController(picker, animated: true)
picker.startScanning()
Objective-C:
initWithSettings:[self currentScanSettings] ];
[self setAllSettingsOnPicker:self.scanditBarcodePicker];
self.scanditBarcodePicker.scanDelegate = self;
UITabBarItem *tabItem = [[UITabBarItem alloc] initWithTitle:@"Scan"
image:[UIImage imageNamed:@"icon_barcode.png"]
tag:3];
self.scanditBarcodePicker.tabBarItem = tabItem;
NSMutableArray *tabControllers = (NSMutableArray *) [[self tabBarController] viewControllers];
[tabControllers addObject:self.scanditBarcodePicker];
[[self tabBarController] setViewControllers:tabControllers];
[[self tabBarController] setSelectedIndex:3];
[self.scanditBarcodePicker startScanning];
Swift:
guard let tabBarController = tabBarController,
let viewControllers = tabBarController.viewControllers else { return }
let picker = SBSBarcodePicker(settings: scanSettings)
picker.scanDelegate = self
let tabItem = UITabBarItem(title: "Scan", image: UIImage(named: "icon_barcode"), tag: 3)
picker.tabBarItem = tabItem
var tabControllers = viewControllers
tabControllers.append(picker)
tabBarController.setViewControllers(tabControllers, animated: true)
tabBarController.selectedIndex = 3
picker.startScanning()