Hi guys,
I'm currently working on a Head Tracking application for visionOS and was wondering if there are any properties or ways to access the position of the app window in an immersive space? I was planning to somehow determine if the window is/is not within the AVP's orientation (through queryDeviceAnchor()) or "visible space". Or is there a way to access a property or data that tells me if the app window is within the user's AVP orientation or not if e.g. the user is turning around having the window behind the back?
I would be extremely thankful for any helpful input!
import SwiftUI
@main
struct HeadTrackingApp: App {
init() {
HeadTrackingSystem.registerSystem()
}
var body: some Scene {
WindowGroup { // Basically getting spatial coordinates of this
ContentView()
}
ImmersiveSpace(id: "appSpace") {
}
}
}
What I was hoping for would be something that I can access that could tell me if the window of the app is either within the visible space of the user
The docs explain this in more detail, but ScenePhase depends on where you place the @Environment(\.scenePhase)
property. If you read this within the App
struct then you will get an aggregate value which informs you if the application is closed. If you read this within a View
struct then it will tell you when the view's scene isn’t currently visible in the UI.
From my experience, the system typically transitions ScenePhases of views to the .background
state after about a minute of being out of view from the user. If you're looking for an immediate indicator of the user not having the window within view this probably won't work for your situation. If you'd like a more general case of the user no longer has been seeing the window this should work great.