Vincent Tourraine

Notes WWDC 2021 : Use the camera for keyboard input in your app

#dev #iOS

Mes notes pour la session Use the camera for keyboard input in your app de la WWDC 2021.

Filtering content

For instance: only scan phone numbers

Based on UITextContentType and UIKeyboardType (for UITextField and UITextView)

New types in iOS 15:

Disable autocorrect to get quick access button above keyboard

Can create explicit button to expose this feature:

let textFromCamera = UIAction.captureTextFromCamera(responder: self.notes, identifier: nil)

Check for availability first:

if !self.notes.canPerformAction(#selector(captureTextFromCamera(:)), withSender: self) {

To support on non-textfield/non-textview, implement UIKeyInput:

class HeadlineImageView: UIImageView, UIKeyInput {
  var headlineLabel: UILabel = UILabel()
  var hasText: Bool = false

  override init(image: UIImage?) {
    super.init(image: image)
  func insertText(_ text: String) {
    headlineLabel.text = text

  func deleteBackward() { }