Vision QR detection and payloadStringValue

Hi to everyone


I'm new to programming and I'm trying to create a simple QR reader using the Vision framework.

Starting with simple tasks, my first goal is to detect a QRCode and simply print its content (a simple string of text) in the debug console.

By following the (few) examples on the Web, I started with thecode below:


    func startBarcodeDetection() {
        let barcodeRequest = VNDetectBarcodesRequest(completionHandler: self.detectBarcodeHandler)
        self.requests = [barcodeRequest]
    }
   
    func detectBarcodeHandler(request: VNRequest, error: Error?) {
        if error != nil {
            print(error!)
        }
        guard let barcodes = request.results else {
            return
        }


Now I get stuck because I really don't know how to handle the Observation part to use the payloadStringValue and make the payload appear in the console, I don't get any error in Xcode with my tries but nothing seems to appear.


PS all examples I've seen so far use the AVCaptureSession to start a video session (if I'm not wrong), since I want to use this QR reader with ARKit, Can I skip the entire AVCaptureSession part?


Thanks in advance and greetings from Italy!