From f0f358a39ec166a50428aa05906282a81740877f Mon Sep 17 00:00:00 2001 From: Alican Akyol <11759370+AlicanAkyol@users.noreply.github.com> Date: Thu, 15 Oct 2026 17:17:29 +0300 Subject: [PATCH] fix(ios): present the print dialog without AppDelegate.window printInteractionControllerParentViewController read [UIApplication sharedApplication].delegate.window, which apps on the UIKit scene life cycle (React Native 0.88 template, Expo SDK 58) do not have, so presenting the print dialog threw '-[AppDelegate window]: unrecognized selector'. Use RCTPresentedViewController(), and RCTKeyWindow() instead of the deprecated keyWindow for the iPad anchors, from the RCTUtils.h this file already imports. --- ios/RNPrint/RNPrint.m | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ios/RNPrint/RNPrint.m b/ios/RNPrint/RNPrint.m index dcc4867..a658de8 100644 --- a/ios/RNPrint/RNPrint.m +++ b/ios/RNPrint/RNPrint.m @@ -63,7 +63,7 @@ -(void)launchPrint:(NSData *) data } }]; } else if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { // iPad - UIView *view = [[UIApplication sharedApplication] keyWindow].rootViewController.view; + UIView *view = RCTKeyWindow().rootViewController.view; [printInteractionController presentFromRect:view.frame inView:view animated:YES completionHandler:completionHandler]; } else { // iPhone [printInteractionController presentAnimated:YES completionHandler:completionHandler]; @@ -152,7 +152,7 @@ -(void)launchPrint:(NSData *) data }; if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { // iPad - UIView *view = [[UIApplication sharedApplication] keyWindow].rootViewController.view; + UIView *view = RCTKeyWindow().rootViewController.view; CGFloat _x = 0; CGFloat _y = 0; if (options[@"x"]){ @@ -170,11 +170,7 @@ -(void)launchPrint:(NSData *) data #pragma mark - UIPrintInteractionControllerDelegate -(UIViewController*)printInteractionControllerParentViewController:(UIPrintInteractionController*)printInteractionController { - UIViewController *result = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; - while (result.presentedViewController) { - result = result.presentedViewController; - } - return result; + return RCTPresentedViewController(); } -(void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController*)printInteractionController {}