@@ -69,12 +69,33 @@ void InstrumentViewDidAppear(FPRUIViewControllerInstrument *instrument,
6969
7070 // This has to be called on the main thread and so it's done here instead of in
7171 // FPRScreenTraceTracker.
72- // TODO(#13067): Replace keyWindow usage (deprecated in iOS and unavailable in visionOS).
7372#if !defined(TARGET_OS_VISION) || !TARGET_OS_VISION
74- #pragma clang diagnostic push
75- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
76- if ([((UIViewController *)_self).view isDescendantOfView: FPRSharedApplication ().keyWindow]) {
77- #pragma clang diagnostic pop
73+ NSArray *windows = nil ;
74+
75+ if (@available (iOS 13.0 , *)) {
76+ NSArray *scenes = FPRSharedApplication ().connectedScenes .allObjects ;
77+ for (UIScreen *scene in scenes) {
78+ if ([scene isKindOfClass: [UIWindowScene class ]]) {
79+ windows = [(UIWindowScene *)scene windows ];
80+ break ;
81+ }
82+ }
83+ } else {
84+ windows = FPRSharedApplication ().windows ;
85+ }
86+
87+ if (!windows || windows.count == 0 ) {
88+ return ;
89+ }
90+
91+ UIWindow *foundKeyWindow = nil ;
92+ for (UIWindow *window in windows) {
93+ if (window.isKeyWindow ) {
94+ foundKeyWindow = window;
95+ break ;
96+ }
97+ }
98+ if (foundKeyWindow && [((UIViewController *)_self).view isDescendantOfView: foundKeyWindow]) {
7899 [[FPRScreenTraceTracker sharedInstance ] viewControllerDidAppear: _self];
79100 }
80101#endif
0 commit comments