Show the scanner

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 view itself (BarcodePicker) is a UIViewController and therefore contains a normal view in iOS. You can add it to the view hierarchy like any other view and add further views on top of the overlay view or the picker itself.

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).

Displaying the scan view modally

// Set app key. This will only have to be done once
License.SetAppKey("yourAppKey");
// Create the scan view. Note that you will have to configure the settings since the
// default settings have all symbologies disabled and you won't be able to scan anything.
BarcodePicker picker = new BarcodePicker (ScanSettings.DefaultSettings ());
// Always show a toolbar (with cancel button) so we can navigate out of the scan view.
picker.OverlayView.ShowToolBar (true);
// Set the delegate to receive callbacks.
scanDelegate = new PickerScanDelegate(this);
picker.ScanDelegate = scanDelegate;
cancelDelegate = new OverlayCancelDelegate(this);
picker.OverlayView.CancelDelegate = cancelDelegate;
// Present the barcode picker modally and start scanning. If you are presenting the controller animated
// you should consider buffering the results while the picker is still animating or only call
// StartScanning() once the animation has finished as you will not be able to close the view controller
// before its present animation has finished.
PresentViewController (picker, true, null);
picker.StartScanning ();

Displaying the scan view in a UINavigationController

// Set app key. This will only have to be done once
License.SetAppKey("yourAppKey");
// Create the scan view. Note that you will have to configure the settings since the
// default settings have all symbologies disabled and you won't be able to scan anything.
BarcodePicker picker = new BarcodePicker (ScanSettings.DefaultSettings ());
// Set the delegate to receive scan events.
scanDelegate = new PickerScanDelegate(this);
picker.ScanDelegate = scanDelegate;
// Push the picker on the navigation stack and start scanning.
navigationController.PushViewController (picker, true);
picker.StartScanning ();

Adding the scan view to a UITabViewController

// Set app key. This will only have to be done once
License.SetAppKey("yourAppKey");
// Create the scan view. Note that you will have to configure the settings since the
// default settings have all symbologies disabled and you won't be able to scan anything.
BarcodePicker picker = new BarcodePicker (ScanSettings.DefaultSettings ());
// Set the delegate to receive scan events.
scanDelegate = new PickerScanDelegate(this);
picker.ScanDelegate = scanDelegate;
// Create a tab item for the picker, possibly with an icon.
picker.TabBarItem = new UITabBarItem("Scan", UIImage.FromFile ("icon_barcode.png"), 3);
// Add the picker to the array of view controllers that make up the tabs.
UIViewController[] tabControllers = this.TabBarController.ViewControllers;
UIViewController[] newTabControllers = new UIViewController[tabControllers.Length + 1];
for (int i = 0; i < tabControllers.Length; i++) {
newTabControllers [i] = tabControllers [i];
}
newTabControllers[newTabControllers.Length - 1] = picker;
// And set the array as the tab bar controllers source of tabs again.
TabBarController.ViewControllers = newTabControllers;
// Switch to the last tab, where the picker is located and start scanning.
TabBarController.SelectedIndex = newTabControllers.Length - 1;
picker.StartScanning ();

Adding the scan view as a subview

// Set app key. This will only have to be done once
License.SetAppKey("yourAppKey");
// Create the scan view. Note that you will have to configure the settings since the
// default settings have all symbologies disabled and you won't be able to scan anything.
BarcodePicker picker = new BarcodePicker (ScanSettings.DefaultSettings ());
// Set the delegate to receive scan events.
scanDelegate = new PickerScanDelegate(this);
picker.ScanDelegate = scanDelegate;
// Add the picker to the view controller's view hierarchy
AddChildViewController (picker);
View.AddSubview (picker.View);
picker.DidMoveToParentViewController (this);
picker.View.TranslatesAutoresizingMaskIntoConstraints = false;
// Add constraints to place the picker at the top of the controller with a height of 300 and
// the same width as the controller. Since this is not the aspect ratio of the video preview
// some of the video preview will be cut away at the top and bottom.
NSDictionary views = NSDictionary.FromObjectsAndKeys (
new object[] { picker.View, TopLayoutGuide },
new object[] { "pickerView", "topGuide" });
View.AddConstraints (NSLayoutConstraint.FromVisualFormat ("V:|[topGuide][pickerView(300)]", 0, null, views));
View.AddConstraints (NSLayoutConstraint.FromVisualFormat ("H:|[pickerView]|", 0, null, views));
picker.StartScanning ();