Skip to content

fix(ios): present the print dialog without AppDelegate.window - #237

Open
AlicanAkyol wants to merge 1 commit into
christopherdro:masterfrom
AlicanAkyol:fix/uiscene-presenting-controller
Open

AlicanAkyol wants to merge 1 commit into
christopherdro:masterfrom
AlicanAkyol:fix/uiscene-presenting-controller

Conversation

@AlicanAkyol

Copy link
Copy Markdown

printInteractionControllerParentViewController gets the parent through [[[UIApplication sharedApplication] delegate] window].

With the UIKit scene life cycle the window belongs to the scene delegate and the AppDelegate has no window property. That is the React Native 0.88 template, and Expo SDK 58 (SDK 57 with enableSceneSupport). Apple requires the scene life cycle for apps built with the iOS 27 SDK (TN3187), and App Store uploads need that SDK from April 2027. In such an app, RNPrint.print() throws when it presents the dialog:

-[AppDelegate window]: unrecognized selector sent to instance

Changes, all using RCTUtils.h, which this file already imports:

  • The delegate method returns RCTPresentedViewController(), which walks from the key window's root to the top presented controller, exactly what the loop did.
  • The two iPad anchors use RCTKeyWindow() instead of [UIApplication sharedApplication].keyWindow, deprecated since iOS 13 and unreliable with scenes.

Behaviour is unchanged on the classic AppDelegate life cycle.

Testing: I reproduced this crash pattern, and confirmed the same helpers fix it, with two other libraries on a fresh React Native 0.88.0-rc.4 app in the iOS simulator (react-native-blob-util#498, invertase/react-native-google-mobile-ads#911, the latter now approved). I have not run this library's example app.

Found while adding a UIScene check to NativeKeel, a React Native health-check CLI I maintain.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant