From b86b5f2212b50712315cf5a5ad406f69bf116267 Mon Sep 17 00:00:00 2001 From: huymobile Date: Sat, 3 Oct 2026 01:57:58 +0700 Subject: [PATCH] fix(messaging, ios): guard AppDelegate window access for UIScene apps `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 --- .../ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m index db505abc5c..6c93ca070f 100644 --- a/packages/messaging/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m +++ b/packages/messaging/ios/RNFBMessaging/RNFBMessaging+NSNotificationCenter.m @@ -86,7 +86,9 @@ - (void)application_onDidFinishLaunchingNotification:(nonnull NSNotification *)n [[RNFBMessagingFIRMessagingDelegate sharedInstance] observe]; RCTRootView *rctRootView; + // `window` is optional on UIApplicationDelegate; scene-based apps may not implement it. if ([UIApplication sharedApplication].delegate != nil && + [[UIApplication sharedApplication].delegate respondsToSelector:@selector(window)] && [UIApplication sharedApplication].delegate.window != nil && [UIApplication sharedApplication].delegate.window.rootViewController != nil && [UIApplication sharedApplication].delegate.window.rootViewController.view != nil && @@ -168,6 +170,7 @@ - (void)application_onDidFinishLaunchingNotification:(nonnull NSNotification *)n - (void)application_onDidEnterForeground { isHeadless = NO; if ([UIApplication sharedApplication].delegate != nil && + [[UIApplication sharedApplication].delegate respondsToSelector:@selector(window)] && [UIApplication sharedApplication].delegate.window != nil && [UIApplication sharedApplication].delegate.window.rootViewController != nil && [UIApplication sharedApplication].delegate.window.rootViewController.view != nil &&