Search code examples
iosswiftaugmented-realityarkitrealitykit

How do I scan a QR Code using RealityKit?


I am building an iOS app using RealityKit. I would like to read a QR Code within ARView but cannot find any documentation/tutorials on it.

Any advice/guidance on doing this would be much appreciated! Thanks in advance.


Solution

  • In RealityKit you can RECOGNIZE a QR code or brand-new AppClipCode using image recognition technique. For this create AR Resources directory in Assets.xcassets and place JPEG or PNG images with QR codes there. You can use up to 100 images per project. Then use .image init for your anchor entity.

    let anchor = AnchorEntity(.image(group: "AR Resources", name: "qrCodeImage"))
    anchor.addChild(modelEntity)
    arView.scene.anchors.append(anchor)
    

    Since ARKit and RealityKit have similar capabilities under the hood, read this post for additional information.

    But you can't READ any QR code (I mean extract an info contained in QR) using only RealityKit framework.