79770925

Date: 2025-09-21 15:04:08
Score: 1
Natty:
Report link

Found the solution by digging through this sample project https://developer.apple.com/documentation/RealityKit/composing-interactive-3d-content-with-realitykit-and-reality-composer-pro

Note that the accompanying WWDC video presents a different method, which throws compiler errors, so ignore that. Thanks Apple!

struct MyAugmentedView : View {

    private let notificationTrigger = NotificationCenter.default.publisher(for: Notification.Name("RealityKit.NotificationTrigger"))

    var body: some View {

        // Add the following modifier to your RealityView or ARView:
        .onReceive(notificationTrigger) { output in
            guard
                let notificationName = output.userInfo?["RealityKit.NotificationTrigger.Identifier"] as? String
                else { return }
                    
                switch notificationName {
                    case "MyFirstNotificationIdentifier" :
                        // code to run when this notification received here
                    case "MySecondNotificationIdentifier"
                        // etc
                    default:
                        return
                }
        }
    }
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: MightyMeta