Skip to content

Commit 00a5aa9

Browse files
SnowingFoxmeta-codesync[bot]
authored andcommitted
Fix RCTAppearance setColorScheme crashing CarPlay apps (non-UIWindowScene guard) (#57876)
Summary: Fixes #57863 `RCTAppearance setColorScheme:` (also reached via `Appearance.setColorScheme()` and `setUserInterfaceStyle`) iterates `RCTSharedApplication().connectedScenes` and reads `scene.windows` on every scene. `connectedScenes` contains `UIScene` objects of any class, and a CarPlay `CPTemplateApplicationScene` is a `UIScene` that does not implement `windows`, so the message send raises `-[CPTemplateApplicationScene windows]: unrecognized selector` and the app aborts. Fix: guard each scene with `isKindOfClass:[UIWindowScene class]` and skip non-`UIWindowScene` objects before touching `.windows`, mirroring the existing pattern already used in `RCTUtils.mm` (`if (![scene isKindOfClass:[UIWindowScene class]]) { continue; }`). Note: `RCTDevMenu.mm` `showOnShake` has the same unguarded `for (UIWindowScene *scene ...)` loop and would crash identically in a CarPlay context; left untouched here to keep this fix minimal, but it should get the same guard. ## Changelog: [IOS] [FIXED] - RCTAppearance.setColorScheme() no longer crashes CarPlay apps when connectedScenes contains a non-UIWindowScene Pull Request resolved: #57876 Test Plan: No jest path exists for this code: it is Objective-C, iOS-only, and iOS cannot be built in the Linux environment this PR was developed in. Correctness is by code inspection. Commands run (in the branch worktree): - `git diff packages/react-native/React/CoreModules/RCTAppearance.mm` — confirms the only change is the 3-line guard: ```diff for (UIWindowScene *scene in RCTSharedApplication().connectedScenes) { + if (![scene isKindOfClass:[UIWindowScene class]]) { + continue; + } [windows addObjectsFromArray:scene.windows]; } ``` - Code inspection of the edited region in full: ```objc - (void)setColorScheme:(NSString *)style { UIUserInterfaceStyle userInterfaceStyle = [RCTConvert UIUserInterfaceStyle:style]; NSMutableArray<UIWindow *> *windows = [NSMutableArray new]; for (UIWindowScene *scene in RCTSharedApplication().connectedScenes) { if (![scene isKindOfClass:[UIWindowScene class]]) { continue; } [windows addObjectsFromArray:scene.windows]; } for (UIWindow *window in windows) { window.overrideUserInterfaceStyle = userInterfaceStyle; } } ``` The guard makes `setColorScheme` tolerate any non-`UIWindowScene` object in `connectedScenes` by skipping it before the `.windows` message send. `isKindOfClass:` is safe to send to any `UIScene` (all are `NSObject`-derived), so the previously-crashing path is unreachable for CarPlay scenes. This matches the reporter's production `patch-package` fix that has been field-tested on-device since 2026-08-02. Reviewed By: cipolleschi Differential Revision: D115451211 Pulled By: christophpurrer fbshipit-source-id: ce372259d908355fff077b17df828308f75bffcf
1 parent c0a4e14 commit 00a5aa9

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

packages/react-native/React/CoreModules/RCTAppearance.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ - (void)setColorScheme:(NSString *)style
114114
UIUserInterfaceStyle userInterfaceStyle = [RCTConvert UIUserInterfaceStyle:style];
115115
NSMutableArray<UIWindow *> *windows = [NSMutableArray new];
116116
for (UIWindowScene *scene in RCTSharedApplication().connectedScenes) {
117+
if (![scene respondsToSelector:@selector(windows)]) {
118+
continue;
119+
}
117120
[windows addObjectsFromArray:scene.windows];
118121
}
119122

0 commit comments

Comments
 (0)