We are also facing similar issue.
Our app runs perfectly in the VisionOS Simulator but does not display any content in the actual device (Vision Pro with OS version: 1.3).
The expected behaviour is, when the app launches, a video will play in a Window and when the video ends it will open another information window. After a series of information windows we open a immersive space to handle 3D elements.
We have set "Preferred Default Scene Session Role" as “Window Application Session Role“ as suggested in the above thread. Despite that we are facing the above issue. Below is the code and any advice will be helpful.
import SwiftUI
@main
struct myApp: App {
@StateObject var sharedData = SharedDataModel()
@State private var isFactoryEnabled = false
var body: some Scene {
WindowGroup(id: "LaunchScreen", content: {
LaunchScreen()
})
.windowStyle(.plain)
.environmentObject(sharedData)
WindowGroup(id: "LoginView", content: {
ZStack {
let _ = UserDefaults.standard.set(false, forKey: "_UIConstraintBasedLayoutLogUnsatisfiable")
let _ = print(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.path)
LoginView()
}
}).windowStyle(.plain)
.environmentObject(sharedData)
WindowGroup(id: "TrainingSelection", content: {
if !sharedData.showNavigationHintView{
NavigationHintView()
.glassBackgroundEffect()
.cornerRadius(30)
}
else {
TrainingSelection()
}
}).windowStyle(.plain)
.environmentObject(sharedData)
WindowGroup(id: "Salutations", content: {
Salutations()
}).windowStyle(.plain)
.environmentObject(sharedData)
WindowGroup {
ContentView()
}
.environmentObject(sharedData)
ImmersiveSpace(id: "myImmersiveSpace") {
ImmersiveView(viewModel: .init())
}
.environmentObject(sharedData)
}
}
import AVFoundation
import RealityKit
import RealityKitContent
struct LaunchScreen: View {
@State private var player: AVPlayer?
@State private var navigateToContentView = false
@EnvironmentObject var audioPlayer: AudioPlayer
var body: some View {
ZStack {
ZStack {
if navigateToContentView {
WarningView()
.transition(.opacity)
.glassBackgroundEffect()
.cornerRadius(15)
} else {
if let player = player {
AVPlayerView(player: player)
.onAppear {
player.play()
addObserver()
}
.cornerRadius(30)
} else {
Text("Unable to Load the Video")
.foregroundColor(.white)
.onAppear {
loadVideo()
}
}
}
}
.edgesIgnoringSafeArea(.all)
.animation(.easeIn, value: 1)
}
.glassBackgroundEffect()
}
private func loadVideo() {
if let videoUrl = Bundle.main.url(forResource: "launchScreen", withExtension: "mp4") {
player = AVPlayer(url: videoUrl)
} else {
print("Unable to Load the Video")
}
}
private func addObserver() {
NotificationCenter.default.addObserver(
forName: .AVPlayerItemDidPlayToEndTime,
object: player?.currentItem,
queue: .main
) { _ in
self.navigateToContentView = true
}
}
}