I’ve a primary UIKit app (created from Xcode template), and modified it to take away loading from storyboard, as a result of I need to create the app’s window programmatically as an alternative of utilizing a storyboard. This works effective when the app is run in an iPhone or iPad simulator, however the app crashes when run on an Apple Imaginative and prescient simulator (when constructing with the visionOS SDK).
That is the code I take advantage of to create the window within the SceneDelegate class:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, choices connectionOptions: UIScene.ConnectionOptions) {
print("SceneDelegate - willConnectTo session")
guard let windowScene = scene as? UIWindowScene else { return }
window = UIWindow(windowScene: windowScene)
window?.backgroundColor = UIColor.systemBackground
window?.rootViewController = ViewController()
window?.makeKeyAndVisible() // crashes right here in Apple Imaginative and prescient system
}
The crash I get is on the “window?.makeKeyAndVisible” line:
*** Assertion failure in BOOL _UIWindowSceneCompatibleIsHidden(UIWindow *__strong)(), UIWindowScene.m:2732
Right here is the stack hint that the Xcode debugger exhibits:
*** Terminating app as a consequence of uncaught exception 'NSInternalInconsistencyException', motive: 'Error in UIKit consumer: window visibility should match its layer visibility!'
*** First throw name stack:
(
0 CoreFoundation 0x00000001804a510c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x0000000180082f50 objc_exception_throw + 56
2 Basis 0x0000000180d41024 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
3 UIKitCore 0x0000000185570000 _UIWindowSceneCompatibleIsHidden + 200
4 UIKitCore 0x0000000185570ca4 -[UIWindowScene _windowUpdatedVisibility:] + 212
5 UIKitCore 0x000000018532f264 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 188
6 UIKitCore 0x0000000185330128 -[UIWindow _setHidden:forced:] + 228
7 UIKitCore 0x000000018533f024 -[UIWindow _mainQueue_makeKeyAndVisible] + 36
8 TestMultiWindowCDApp 0x00000001047d073c $s20TestMultiWindowCDApp13SceneDelegateC5scene_13willConnectTo7optionsySo7UISceneC_So0L7SessionCSo0L17ConnectionOptionsCtF + 844
9 TestMultiWindowCDApp 0x00000001047d08a8 $s20TestMultiWindowCDApp13SceneDelegateC5scene_13willConnectTo7optionsySo7UISceneC_So0L7SessionCSo0L17ConnectionOptionsCtFTo + 84
10 UIKitCore 0x00000001847ef76c +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1012
11 UIKitCore 0x00000001852fafd0 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 804
12 UIKitCore 0x00000001852fb2b8 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 356
13 UIKitCore 0x0000000184dda1b4 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 260
14 FrontBoardServices 0x0000000186e4851c -[FBSScene _callOutQueue_didCreateWithTransitionContext:completion:] + 296
15 FrontBoardServices 0x0000000186e71d48 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.90 + 224
16 FrontBoardServices 0x0000000186e55390 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
17 FrontBoardServices 0x0000000186e71ac0 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 284
18 libdispatch.dylib 0x0000000105a567e4 _dispatch_client_callout + 16
19 libdispatch.dylib 0x0000000105a5a3dc _dispatch_block_invoke_direct + 392
20 FrontBoardServices 0x0000000186e95aa8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
21 FrontBoardServices 0x0000000186e95984 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 196
22 FrontBoardServices 0x0000000186e95adc -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 24
23 CoreFoundation 0x0000000180405be8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
24 CoreFoundation 0x0000000180405b30 __CFRunLoopDoSource0 + 172
25 CoreFoundation 0x00000001804052f8 __CFRunLoopDoSources0 + 320
26 CoreFoundation 0x00000001803ff9b8 __CFRunLoopRun + 768
27 CoreFoundation 0x00000001803ff2b4 CFRunLoopRunSpecific + 572
28 GraphicsServices 0x000000018e9b6c20 GSEventRunModal + 160
29 UIKitCore 0x00000001852f9c70 -[UIApplication _run] + 868
30 UIKitCore 0x00000001852fd910 UIApplicationMain + 124
31 UIKitCore 0x000000018478b890 __swift_destroy_boxed_opaque_existential_1Tm + 10528
32 TestMultiWindowCDApp 0x00000001047cf67c $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 120
33 TestMultiWindowCDApp 0x00000001047cf5f4 $s20TestMultiWindowCDApp11AppDelegateC5$mainyyFZ + 44
34 TestMultiWindowCDApp 0x00000001047cf750 principal + 28
35 dyld 0x0000000104e9d544 start_sim + 20
36 ??? 0x000000010482e058 0x0 + 4370653272
37 ??? 0x2311800000000000 0x0 + 2526941603419914240
)
libc++abi: terminating as a consequence of uncaught exception of sort NSException
I do get a window
object once I use UIWindow(windowScene: windowScene)
Any concepts what this error means, and/or easy methods to resolve it?