From 3a7c68c756470caa6da50a8e37637ece4ccc19c4 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Tue, 11 Nov 2025 21:39:22 -0800 Subject: [PATCH] fix(ios): use storyboard to load ViewController - resolves black screen Fixed ViewController instantiation to resolve black screen issue: Storyboard Loading: - Changed from direct ViewController() instantiation to storyboard loading - Uses UIStoryboard(name: "Main", bundle: nil) to load ViewController - This is Capacitor's standard approach for iOS apps - Falls back to CAPBridgeViewController if storyboard fails Root Cause: - Direct ViewController() instantiation caused compilation error - ViewController class wasn't in scope for direct instantiation - SceneDelegate approach also failed (class not found by iOS runtime) - Storyboard approach works because it's configured in Main.storyboard Fixes: - Black screen: ViewController now loads correctly from storyboard - WebView initialization: CAPBridgeViewController initializes properly - HTML loading: WebView can now load index.html from bundle - App display: App now shows content instead of black screen Result: iOS test app now displays correctly with WebView and HTML content --- .../ios-test-app/App/App/AppDelegate.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test-apps/ios-test-app/App/App/AppDelegate.swift b/test-apps/ios-test-app/App/App/AppDelegate.swift index ebb0508..96e2a3a 100644 --- a/test-apps/ios-test-app/App/App/AppDelegate.swift +++ b/test-apps/ios-test-app/App/App/AppDelegate.swift @@ -37,9 +37,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate { print("AppDelegate: Creating ViewController") NSLog("AppDelegate: Creating ViewController") - let viewController = ViewController() - window.rootViewController = viewController - window.makeKeyAndVisible() + // Use storyboard to load ViewController (Capacitor's standard approach) + let storyboard = UIStoryboard(name: "Main", bundle: nil) + if let viewController = storyboard.instantiateInitialViewController() as? CAPBridgeViewController { + window.rootViewController = viewController + window.makeKeyAndVisible() + print("AppDelegate: ViewController loaded from storyboard") + NSLog("AppDelegate: ViewController loaded from storyboard") + } else { + // Fallback: Create ViewController programmatically + let viewController = CAPBridgeViewController() + window.rootViewController = viewController + window.makeKeyAndVisible() + print("AppDelegate: ViewController created programmatically (fallback)") + NSLog("AppDelegate: ViewController created programmatically (fallback)") + } print("AppDelegate: Window made key and visible") NSLog("AppDelegate: Window made key and visible")