@@ -53,6 +53,22 @@ impl IOS {
5353 pub fn new ( ) -> Self {
5454 Self :: default ( )
5555 }
56+
57+ /// Helper function to get the topmost view controller for presenting the alert.
58+ ///
59+ /// Returns `None` if no active window or view controller is found.
60+ pub fn get_top_view_controller ( mtm : MainThreadMarker ) -> Option < Retained < UIViewController > > {
61+ let key_window = UIApplication :: sharedApplication ( mtm)
62+ . connectedScenes ( )
63+ . iter ( )
64+ . filter_map ( |scene| scene. downcast :: < UIWindowScene > ( ) . ok ( ) )
65+ . find_map ( |scene| scene. keyWindow ( ) ) ?;
66+ let mut top_vc = key_window. rootViewController ( ) ?;
67+ while let Some ( presented) = top_vc. presentedViewController ( ) {
68+ top_vc = presented;
69+ }
70+ Some ( top_vc)
71+ }
5672}
5773
5874impl Backend for IOS {
@@ -198,7 +214,7 @@ impl Backend for IOS {
198214 ) ;
199215 alert. addAction ( & ok_action) ;
200216
201- let top_vc = get_top_view_controller ( mtm) . ok_or_else ( || {
217+ let top_vc = Self :: get_top_view_controller ( mtm) . ok_or_else ( || {
202218 io:: Error :: other (
203219 "no active window or view controller found to present the input dialog" ,
204220 )
@@ -208,19 +224,3 @@ impl Backend for IOS {
208224 Ok ( ( ) )
209225 }
210226}
211-
212- /// Helper function to get the topmost view controller for presenting the alert.
213- ///
214- /// Returns `None` if no active window or view controller is found.
215- pub fn get_top_view_controller ( mtm : MainThreadMarker ) -> Option < Retained < UIViewController > > {
216- let key_window = UIApplication :: sharedApplication ( mtm)
217- . connectedScenes ( )
218- . iter ( )
219- . filter_map ( |scene| scene. downcast :: < UIWindowScene > ( ) . ok ( ) )
220- . find_map ( |scene| scene. keyWindow ( ) ) ?;
221- let mut top_vc = key_window. rootViewController ( ) ?;
222- while let Some ( presented) = top_vc. presentedViewController ( ) {
223- top_vc = presented;
224- }
225- Some ( top_vc)
226- }
0 commit comments