RealityKit: run function on image detection

I am looking to run a function when an a reference image is detected in an ARView. I am using RealityKit.

The process would be as follows:
  1. create ARView with image detection

  2. detect image

  3. run function to fetch data (changes based on time image is found at)

  4. produce AR object in ARView using data retrieved

How do I run the function to fetch data?
When an image is detected, an ARImageAnchor will be added for the detected image in session(_:didAdd:). When an image anchor is added, you can call your function. Make sure that you set the ARSession's delegate to the object that you have conformed to ARSessionDelegate, usually this object would be your view controller.

That make sense, but I am unsure how to do that using my current code. I am unfamiliar with ARKit and ARSession.

Code Block
// create ARView
let arView = ARView(frame: .zero,
cameraMode: .ar,
automaticallyConfigureSession: true)
// create anchor using an image and add it to the ARView
let target = AnchorEntity(.image(group: "AR Resources", name: "some_image"))
// add anchor to AR world
arView.scene.anchors.append(target)
// add objects to anchor to display in ARView
// Custom function that adds a plane and text to anchor
addARObjs(anchor: target, title: title)
// return the view with objects anchored the image
return arView


RealityKit: run function on image detection
 
 
Q