fix(cli): keep a storyboard CAPBridgeViewController subclass when migrating to UIScene

RE
3d ago
+72-1

Problem

Since 8.5 the template SceneDelegate creates the root view controller in code (window?.rootViewController = CAPBridgeViewController()). The view controller in Main.storyboard is still instantiated through UISceneStoryboardFile but never loaded.

The Custom ViewController docs tell people to subclass CAPBridgeViewController and set it as the custom class in Main.storyboard, and that is also how local plugins are registered. When cap migrate runs on such an app, it writes the template SceneDelegate, the subclass is silently dropped, and capacitorDidLoad() never runs, so local plugins stop being registered. The app builds and launches without any error.

The 8.5 update guide does mention this ("instantiate it here instead of setting it in the storyboard"), but the automated migration doesn't apply it.

Change

When writing SceneDelegate.swift, migrateToUIScene reads Base.lproj/Main.storyboard. If the initial view controller has a custom class other than CAPBridgeViewController, it instantiates that class instead, and logs that it did. Projects using the stock storyboard get exactly the template file, as before.

Testing

  • New cli/test/migrate-uiscene-storyboard.spec.ts runs against the shipped storyboard and SceneDelegate: the stock storyboard gives no subclass, a custom class is detected, and the SceneDelegate swap is applied.
  • Full CLI suite passes after npm run build: 14 suites, 145 tests. ESLint, Prettier and tsc --noEmit are clean.
  • End to end on the iOS 27.2 simulator. I took a fresh cap add ios project and reset it to the pre-8.5 state (no scene manifest, no SceneDelegate.swift, no configurationForConnecting). Then I added MyViewController: CAPBridgeViewController, logging from capacitorDidLoad(), set as the storyboard's custom class.
    • Before this change: a probe on the stock 8.5 template showed only the SceneDelegate's controller loads, so the storyboard class is never used.
    • With this change: the migration logs SceneDelegate.swift uses your MyViewController from Main.storyboard as the root view controller. The app builds, and MyViewController.capacitorDidLoad() runs at launch.

Related: #8714 (doctor warning for projects that haven't adopted UIScene). I'll send a docs PR to update the Custom ViewController page for 8.5+.

🤖 Generated with Claude Code