i just started to test the DataScannerViewController on my Apple Vision Pro. The documentation says that it is available for vision OS 1.0+ (https://developer.apple.com/documentation/visionkit/datascannerviewcontroller), but if i start the Sample Code from here: https://developer.apple.com/documentation/visionkit/scanning-data-with-the-camera. The Log says it is not supported.
Does anyone know whats going on?
@MainActor
struct DocumentScannerView: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: DataScannerViewController, context: Context) {
}
var scannerViewController: DataScannerViewController = DataScannerViewController(
recognizedDataTypes: [.text(), .barcode()],
qualityLevel: .accurate,
recognizesMultipleItems: false,
isHighFrameRateTrackingEnabled: false,
isHighlightingEnabled: true
)
func makeUIViewController(context: Context) -> DataScannerViewController {
scannerViewController.delegate = context.coordinator
// Add a button to start scanning
let scanButton = UIButton(type: .system)
scanButton.backgroundColor = UIColor.systemBlue
scanButton.setTitle("Start Scan", for: .normal)
scanButton.setTitleColor(UIColor.white, for: .normal)
scanButton.addTarget(context.coordinator, action: #selector(Coordinator.startScanning(_:)), for: .touchUpInside)
scannerViewController.view.addSubview(scanButton)
// Set up button constraints
scanButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
scanButton.centerXAnchor.constraint(equalTo: scannerViewController.view.centerXAnchor),
scanButton.bottomAnchor.constraint(equalTo: scannerViewController.view.safeAreaLayoutGuide.bottomAnchor, constant: -20)
])
return scannerViewController
}
func makeCoordinator() -> Coordinator {
return Coordinator(self)
}
class Coordinator: NSObject, DataScannerViewControllerDelegate {
var parent: DocumentScannerView
var roundBoxMappings: [UUID: UIView] = [:]
init(_ parent: DocumentScannerView) {
self.parent = parent
}
// DataScannerViewControllerDelegate - methods starts here
func dataScanner(_ dataScanner: DataScannerViewController, didAdd addedItems: [RecognizedItem], allItems: [RecognizedItem]) {
//ToDo
}
func dataScanner(_ dataScanner: DataScannerViewController, didRemove removedItems: [RecognizedItem], allItems: [RecognizedItem]) {
//ToDo
}
func dataScanner(_ dataScanner: DataScannerViewController, didUpdate updatedItems: [RecognizedItem], allItems: [RecognizedItem]) {
//ToDo
}
func dataScanner(_ dataScanner: DataScannerViewController, didTapOn item: RecognizedItem) {
//ToDo
}
// DataScannerViewControllerDelegate - methods ends here
// Add this method to start scanning
@objc func startScanning(_ sender: UIButton) {
do {
try parent.scannerViewController.startScanning()
} catch let error {
print("Error: \(error.localizedDescription)")
}
}
}
}
Apple has provided a compatibility list here
For this particular ViewController you can use to confirm compatibility.
The "Notes" app uses the iPhone to scan the document and then passes it on to the VisionPro via iCloud.