ios – ARKit add AR Reference Photos from url by scanning QR code


My app is about AR Picture Monitoring. I need to obtain Reference photos to trace by scanning QR code. I’ve applied: downloading photos by url and including it into reference photos, however I wish to obtain photos after QR code scanned (the place the url is positioned).
I’ve tried to make use of ARSCNView with AVCaptureSession to detect QR code. However my app FREEZED after including capturesession.
Might you assist? What am I doing mistaken? Please recommendation how you can do it in correct means?

    sceneView.delegate = self
    let scene = SCNScene(named: "artwork.scnassets/ship.scn")!
    sceneView.scene = scene

    let configuration = ARImageTrackingConfiguration()
    let arImages = newReferenceImages
    configuration.trackingImages = arImages
    sceneView.session.run(configuration)

AR photos detecting

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) 
  {
    guard anchor is ARImageAnchor else { return }
    guard let referenceImage = ((anchor as? ARImageAnchor)?.referenceImage) else { 
    return }
    
    guard let container = sceneView.scene.rootNode.childNode(withName: "container", 
    recursively: false) else { return }
    container.removeFromParentNode()
    node.addChildNode(container)
    container.isHidden = false
    
    guard let id = referenceImage.title?.cut up(separator: "-")[1].description else { 
    return }
    CacheManager.shared.getPathForFiLe(title: "video-" + id) { [weak self] lead to
        guard let `self` = self else { return }
        self.videoURL = URL(string: end result)
    }
    
    guard let videoURL = self.videoURL else { return }
    videoPlayer = AVPlayer(url: videoURL)
    let videoScene = SKScene(dimension: CGSize(width: 720.0, peak: 1280.0))
    videoNode = SKVideoNode(avPlayer: videoPlayer)
    videoNode.place = CGPoint(x: videoScene.dimension.width/2, y: videoScene.dimension.peak/2)
    videoNode.dimension = videoScene.dimension
    videoNode.yScale = -1
    videoNode.play()
    videoScene.addChild(videoNode)
    
    guard let video = container.childNode(withName: "video", recursively: true) else { return }
    video.geometry?.firstMaterial?.diffuse.contents = videoScene
    video.scale = SCNVector3(x: Float(referenceImage.physicalSize.width), y: Float(referenceImage.physicalSize.peak), z: 1.0)
    video.place = node.place
    // For Animation
    guard let videoContainer = container.childNode(withName: "videoContainer", recursively: false) else { return }
    videoContainer.runAction(SCNAction.sequence([SCNAction.wait(duration: 1.0), SCNAction.scale(to: 1.0, duration: 0.5)]))
}

For QR code scanning

 func configureQRsession() {
    captureSession = AVCaptureSession()
    guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else { return }
    let videoInput: AVCaptureDeviceInput

    do {
        videoInput = attempt AVCaptureDeviceInput(system: videoCaptureDevice)
    } catch {
        return
    }

    if (captureSession.canAddInput(videoInput)) {
        captureSession.addInput(videoInput)
    } else {
        failed()
        return
    }

    let metadataOutput = AVCaptureMetadataOutput()

    if (captureSession.canAddOutput(metadataOutput)) {
        captureSession.addOutput(metadataOutput)

        metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.important)
        metadataOutput.metadataObjectTypes = [.qr]
    } else {
        failed()
        return
    }

    previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
    previewLayer.body = view.layer.bounds
    previewLayer.videoGravity = .resizeAspectFill
    view.layer.addSublayer(previewLayer)

    captureSession.startRunning()
}