steventroughtonsmith / VisionVolumetricUIKit

Present a volumetric window from UIKit on visionOS
32 stars 1 forks source link

How does it work the spawning of child windows will reality kit volumes? #2

Closed ManjitBedi closed 3 months ago

ManjitBedi commented 3 months ago

First, thanks for sharing the example code.

When I run the app in the visionOS simulator and on a AVP, the tapping of a button does not do anything to spawn a child volume. I do see the SwifIU of the content view does work in the Xcode preview

I am not familiar with how this code works, I changed the bundle ID but still does not work. Is there an additional setting somewhere in Xcode for the scene options?

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {

        if options.userActivities.filter({$0.activityType == "com.noorg.child"}).first != nil {
            print("create child window?")
            return UISceneConfiguration(name: "Child", sessionRole: .windowApplicationVolumetric)
        } else {
            print("scene session")
        }

        return UISceneConfiguration(name: "Default", sessionRole: .windowApplication)
    }
ManjitBedi commented 3 months ago

I added some debug & I get this error:

Failed to activate scene session: Scene session activation failed because the requested role "UIWindowSceneSessionRoleVolumetricApplication" is not supported.
steventroughtonsmith commented 3 months ago

My understanding is this functionality was removed (or gated by private API) before the release of visionOS 1.0. It is no longer viable

ManjitBedi commented 3 months ago

I see, thanks for the quick reply.

ManjitBedi commented 3 months ago

FYI, after much hacking & searching online, I was able to achieve something. I should type up some notes & make some demo code 🤔.

I was able to get a UIKit based app working with SwiftUI & visionOS by:

    <key>UIApplicationSceneManifest</key>
        <dict>
            <key>UIApplicationSupportsMultipleScenes</key>
            <true/>
            <key>UISceneConfigurations</key>
            <dict>
                <key>UIWindowSceneSessionRoleApplication</key>
                <array>
                    <dict>
                        <key>UISceneConfigurationName</key>
                        <string>Default Configuration</string>
                        <key>UISceneDelegateClassName</key>
                        <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                    </dict>
                </array>
            </dict>
        </dict>

struct ContentView: View { @Environment(.openWindow) private var openWindow

var body: some View {
    ZStack {
        StoryboardView(storyboardName: "Main_visionOS", identifier: "splash")
    }
}

}

struct StoryboardView: UIViewControllerRepresentable { let storyboardName: String let identifier: String

func makeUIViewController(context: Context) -> UIViewController {
    let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
    return storyboard.instantiateViewController(withIdentifier: identifier)
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}

}


- Scene delegate
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = scene as? UIWindowScene else { return }

    let window = UIWindow(windowScene: windowScene)
    window.rootViewController = UIHostingController(rootView: ContentView())
    self.window = window
    window.makeKeyAndVisible()
}