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
This commit is contained in:
Matthew Raymer
2025-11-11 21:39:22 -08:00
parent 3250b3fc33
commit 3a7c68c756

View File

@@ -37,9 +37,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("AppDelegate: Creating ViewController") print("AppDelegate: Creating ViewController")
NSLog("AppDelegate: Creating ViewController") NSLog("AppDelegate: Creating ViewController")
let viewController = ViewController() // 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.rootViewController = viewController
window.makeKeyAndVisible() 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") print("AppDelegate: Window made key and visible")
NSLog("AppDelegate: Window made key and visible") NSLog("AppDelegate: Window made key and visible")