Repository navigation
fix(messaging, ios): guard AppDelegate window access for UIScene apps - #9359
huytdps13400 wants to merge 1 commit into
Conversation
|
|
`window` is an optional UIApplicationDelegate property. Apps on the UIScene life cycle often drop it from their AppDelegate, so reading `delegate.window` raised an unrecognized-selector exception at launch and when entering the foreground. Check respondsToSelector first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c9b5a38 to
b86b5f2
Compare
mikehardy
left a comment
There was a problem hiding this comment.
Hey @huytdps13400 👋
Thanks for this — clean, minimal fix for a real crash on scene-only AppDelegates (the ones that actually omit window, which our fixtures intentionally keep around for other probes). I scanned the rest of the library for the same delegate.window pattern and this looks like the only spot.
I rebased onto current main so it is ready to land. Planning to cut a release with this shortly.
Cheers
|
Hey @huytdps13400 👋 Thanks again for the fix — the approach was exactly right. We could not merge this PR because the CLA was not signed, so I re-implemented the same guard on a fresh branch and opened a replacement: Going to close this one as obsolete in favor of that. Really appreciate you digging into the UIScene crash path. Cheers |
|
Obsolete in favor of #9375 (CLA). Same fix, maintainer re-implementation. |
Description
RNFBMessaging+NSNotificationCenter.mreads[UIApplication sharedApplication].delegate.windowinapplication_onDidFinishLaunchingNotification:andapplication_onDidEnterForeground.windowis an optional property onUIApplicationDelegate. Apps that use the UIScene life cycle often remove it from their AppDelegate, because the window belongs to the scene delegate. For those apps the read throws-[AppDelegate window]: unrecognized selector sent to instanceat launch.This PR adds a
respondsToSelector:@selector(window)check before thewindowreads in both places. If the delegate has nowindow, the code skips theRCTRootViewisHeadlessappProperties update, which already happens whenwindowis nil. TheisHeadlessflag on the module is still set. Apps whose AppDelegate keepswindow, like the e2e app andtest-rn-bare, behave the same as before.Related issues
Fixes #8796
Release Summary
fix(messaging, ios): no longer crash at launch in UIScene apps whose AppDelegate has no
windowpropertyChecklist
AndroidiOSOther(macOS, web)e2etests added or updated inpackages/\*\*/e2ejesttests added or updated inpackages/\*\*/__tests__Test Plan
The repo has no native unit-test target for this file, and the e2e app keeps
AppDelegate.windowon purpose, so e2e can't hit this path. I tested it with a small out-of-tree harness instead. The harness compiles the realRNFBMessaging+NSNotificationCenter.mfor Mac Catalyst against UIKit, with stub headers for React, RNFBApp and Firebase. It swaps+[UIApplication sharedApplication]for a fake app and calls both notification handlers directly:windowproperty, background launch from a remote notification, then foreground.window.rootViewController.viewis anRCTRootViewwithisHeadless: NO. This checks that appProperties still change toYESon a headless launch and back toNOon foreground.Before (main @ c147145):
After:
clang-format --style=Google -n -Werror(thelint:ios:checkconfig, clang-format 1.7.0) passes on the messaging iOS sources.This fix was prepared with AI assistance (Claude Code) and verified locally with the tests above.
🔥
🤖 Generated with Claude Code