Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2021 Photos & Camera

WWDC21 · 12 min · Photos & Camera

Use the camera for keyboard input in your app

Learn how you can support Live Text and intelligently pull information from the camera to fill out forms and text fields in your app. We’ll show you how to apply content filtering to capture the correct information when someone uses the camera as keyboard input and apply it to a relevant UITextField, helping your app input data like phone numbers, addresses, and flight information. And we’ll explore how you can create a custom interface, extend other controls like UIImageViews to support this capability, and more. For more on supporting Autofill in your app, we recommend watching “Autofill everywhere” from WWDC20 and “The Keys to a Better Text Input Experience” from WWDC17.

Watch at developer.apple.com ↗

Transcript all transcripts

Code shown on screen · 4 snippets

Filtering text field input swift · at 3:33 ↗
phone.keyboardType = .phonePad
phone.autocorrectionType = .no

address.textContentType = .fullStreetAddress
Custom action to capture text from camera swift · at 5:07 ↗
let textFromCamera = UIAction.captureTextFromCamera(responder: self.notes, identifier: nil)
Adding custom UIAction for capture text to a menu swift · at 5:41 ↗
let textFromCamera = UIAction.captureTextFromCamera(responder: self.notes, identifier: nil)

let choosePhotoOrVideo = UIAction()
let takePhotoOrVideo = UIAction()
let scanDocuments = UIAction()

let cameraMenu = UIMenu(children: [choosePhotoOrVideo, takePhotoOrVideo, scanDocuments, textFromCamera])

let menuToolbarItem = UIBarButtonItem(title: nil, image: UIImage(systemName: "camera.badge.ellipsis"), primaryAction: nil, menu: cameraMenu)
Implementing UIKeyInput on a custom image view swift · at 9:59 ↗
class HeadlineImageView: UIImageView, UIKeyInput {
    var headlineLabel: UILabel = UILabel()
    var hasText: Bool = false

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

    func deleteBackward() { }
}