certain QR codes are not readable?

I have done code for reading QR code but it sometimes does not read certain types of QR code.

IOS and google chrome is able to read codes no matter how they are, how to get the same kind of functionality...


Code Block
output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
 output.metadataObjectTypes = [
AVMetadataObject.ObjectType.qr,
AVMetadataObject.ObjectType.dataMatrix
]


code that I used for reading QR code as follows

Code Block
class ViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
    var video = AVCaptureVideoPreviewLayer()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        //create session
        let session = AVCaptureSession()
        
        //Define capture device
        let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)
        
        do
        {
            let input = try AVCaptureDeviceInput(device: captureDevice!)
            session.addInput(input)
        }
        catch
        {
            print("ERROR")
        }
        
        let output = AVCaptureMetadataOutput()
        session.addOutput(output)
        
        output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
        
        output.metadataObjectTypes = [AVMetadataObject.ObjectType.qr, AVMetadataObject.ObjectType.dataMatrix]
        
        video = AVCaptureVideoPreviewLayer(session: session)
        video.frame = view.layer.bounds
        view.layer.addSublayer(video)
        
        session.startRunning()
    }
    
    func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
        
        if metadataObjects != nil && metadataObjects.count != nil {
            
            if let object = metadataObjects.first as? AVMetadataMachineReadableCodeObject {
//            if let object = metadataObjects[0] as? AVMetadataMachineReadableCodeObject {
                if object.type == AVMetadataObject.ObjectType.qr {
                    let alert = UIAlertController(title: "QR code", message: object.stringValue, preferredStyle: UIAlertController.Style.alert)
                    alert.addAction(UIAlertAction(title: "Retake", style: UIAlertAction.Style.default, handler: nil))
                    alert.addAction(UIAlertAction(title: "Copy", style: UIAlertAction.Style.default, handler: { (nil) in
                        UIPasteboard.general.string = object.stringValue
                    }))
                    
                    self.present(alert, animated: true, completion: nil)
                }
            }
        }
        
    }
}

certain QR codes are not readable?
 
 
Q