I ran into this today and found a solution. The trick is to use a secondary text field that is off-screen or hidden with a customizable empty set of inputView and make this field the first responder. This field captures text from a hardware scanner, and the software keyboard is hidden.
However, I got this job using a very similar approach and instead made the view controller itself the first responder as an input scan view.
Example:
class SearchViewController: UIViewController, UIKeyInput { let searchField = UITextField() let softwareKeyboardHider = UIView() override func viewDidLoad() { super.viewDidLoad() view.addSubview(searchField) inputAssistantItem.leadingBarButtonGroups = [] inputAssistantItem.trailingBarButtonGroups = [] } override var canBecomeFirstResponder: Bool { return true } override var inputView: UIView? { return softwareKeyboardHider } var hasText: Bool { return searchField.hasText } func insertText(_ text: String) { searchField.insertText(text) } func deleteBackward() { searchField.deleteBackward() } }
Now that you want to hide the soft keyboard, make SearchViewController first responder.
To show the soft keyboard, make SearchViewController.searchField first responder.
source share