Deprecation warning
Please note that this is outdated documentation for an older release of the Scandit Barcode Scanner SDK.
We are deprecating the 5.x API on all platforms (except Linux). Release 5.19 in April 2021 will be our final. Applications running 5.x will continue to work, and we will continue to release critical bug fixes and security patches only, for one year. We encourage you to migrate to 6.x and take advantage of our latest / advanced features and improved performance.
You'll find the updated documentation at: Data Capture SDK Documentation for iOS
The new API introduced with the Scandit Barcode Scanner 4.7 no longer contains a default manual input method that can be displayed to let the user enter the barcode through the use of the keyboard. This adjustment was made because adding your own search bar is very simple and was oftentimes necessary to nicely integrate it into the app around the scanner and customize it accordingly.
This guide will show you how to add a basic search bar to the SBSBarcodePicker. You should adjust the code from this guide to make the search bar match your own needs and your app's look and feel.
Define the properties
Add properties for the UISearchBar, a UITapGestureRecognizer and the SBSBarcodePicker (you probably already have this).
//!
Adding a UISearchBar to the SBSBarcodePicker
To add a search bar to the barcode picker you simply create it and add it to the picker's view. You can then position the search bar through layout constraints. Alternatively you can also add the search bar outside of the picker's view hierarchy (for example on top of it or above it) if that fits better for your app.
If you set the search bar to display a number or decimal pad as the keyboard there will not be a search button included. A good option in that case is to add a toolbar to the keyboards accessory view that contains a button to search as shown here:
Implement the UISearchBarDelegate
Make sure that your view controller implements the UISearchBarDelegate
protocol
//!
In the searchBarTextDidBeginEditing:
callback we want to make the search bar show the cancel button and add a UITapGestureRecognizer that lets us exist the search by tapping the scanner.
In the searchBarTextDidEndEditing:
callback we hide the cancel button again, make the search bar resign first responder status and remove the gesture recognizer again.
When the cancel button is clicked we make the search bar resign first responder status and clear its text.
When the search button is clicked we make the search bar resign first responder status, hide the cancel button and can then process the search bars text.