Correction: Title should read AVCaptureDevice, not AVAudioDevice, of course.
Post
Replies
Boosts
Views
Activity
With this update, Button and Toggle attachments oftentimes don't fire on first load in an immersive space. They always seem to work when the same immersive space is loaded again. Smells like a race condition. I can reproduce this with Xcode's visionOS template project.
@sha921 Is this still supposed to work? As @asbjornu mentioned in their comment the suggested fix doesn't seem to work anymore. I tried around 4 weeks ago and now with Xcode 15 Beta 8, but still no luck.
As of Xcode 15 Beta 8, all existing ARSession DataProviders report as unsupported in the visionOS simulator. Filed this as FB13125675.
I can't speak to CompositorServices, but ARPose seems to have been eradicated from ARKit completely. I'm using the Swift API, but the equivalent C API replacements would be:
ar_world_tracking_provider_query_pose_at_timestamp -> ar_world_tracking_provider_query_device_anchor_at_timestamp
and with ar_device_anchor being a subclass of ar_trackable_anchor being a subclass of ar_anchor
ar_pose_get_origin_from_device_transform -> ar_anchor_get_origin_from_anchor_transform
@Caneto This is a relevant thread, even if it doesn't provide any solution to your problem. Feel free to file a feedback with Apple to put this higher on their list of things to solve.
SwiftUI views in visionOS can be presented as windows via the openWindow enviroment action and as RealityView attachments. Your VideoView is presented as neither. An ImmersiveSpace doesn't know where to put a SwiftUI view on its own in the unbounded full space.
Note that if you go for an attachment, be wary of the recent API changes which seem to be currently undocumented.
Figured it out.
According to the docs, there are two entries that apparently both must be added to Info.plist. Xcode's error message is not helpful in making that understood, since it doesn't reflect the actual error and the missing immersion style can also be set in code.
UIApplicationPreferredDefaultSceneSessionRoleKey: UISceneSessionRoleImmersiveSpaceApplication
UISceneInitialImmersionStyle: UIImmersionStyleMixed / UIImmersionStyleFull / UIImmersionStyleProgressive nested in the scene configurations dictionary under UISceneSessionRoleImmersiveSpaceApplication.
Note: There's also UISceneSessionRoleImmersiveApplication without the Space part. Make sure to use the right one in both places.
I used Xcode's GUI to set it up, but here's the working Info.plist as of Xcode 15.0 beta 8 (15A5229m):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationPreferredDefaultSceneSessionRole</key>
<string>UISceneSessionRoleImmersiveSpaceApplication</string>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UISceneSessionRoleImmersiveSpaceApplication</key>
<array>
<dict>
<key>UISceneInitialImmersionStyle</key>
<string>UIImmersionStyleProgressive</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
This might be the same issue I'm seeing with attachments in the immersive space I mentioned over in this thread. I noticed this happening only with the latest beta 8 and filed a feedback with Apple.
You should give SpatialTapGesture a try. It can be targeted to any or to specific entities with targetedToEntity() or targetedToAnyEntity().
.gesture(
SpatialTapGesture()
.targetedToEntity(self.videoEntity)
.onEnded { _ in
Task {
openWindow(id: "Video")
}
}
)
Since I needed to find a workaround for this issue myself, I played around a little more. As suspected, this definitely is a race condition during the initial RealityView setup. I have a test project set up that adds two buttons and a toggle to the ImmersiveView in Xcode's template project. When I add
try! await Task.sleep(nanoseconds: 100 * NSEC_PER_MSEC)
at the end of the view’s make closure, all three UI elements are always active in the visionOS simulator on my MBP M2 Pro, 8+4 cores, 16 GB.
When I go down to 50 * NSEC_PER_MSEC, all of the UI elements work (most of the time - I’ve had a case where two of the three were active, but the third one, that is added last, wasn’t).
When I go down to 30 * NSEC_PER_MSEC, all of the UI elements sometimes work.
When I go down to 20 * NSEC_PER_MSEC, none of the UI elements work.
Looks a lot like an ornament to me.
Also
let cameraTransform = Transform(matrix: pose.originFromDeviceTransform)
needs to become
let cameraTransform = Transform(matrix: pose.originFromAnchorTransform)
Attachments work differently now, as well, so that for example
} attachments: {
Text("Preview")
.font(.system(size: 100))
.background(.pink)
.tag("previewTag")
}
needs to become
} attachments: {
Attachment(id: "previewTag") {
Text("Preview")
.font(.system(size: 100))
.background(.pink)
}
}
@calebmitcler I based my code off the Xcode template app project for visionOS, so my app struct is simply this:
@main
struct ImmersiveSpaceTestApp: App {
var body: some Scene {
ImmersiveSpace(id: "ImmersiveSpace") {
ImmersiveView()
}
}
}