diff --git a/FirebasePerformance/Sources/Instrumentation/UIKit/FPRUIViewControllerInstrument.m b/FirebasePerformance/Sources/Instrumentation/UIKit/FPRUIViewControllerInstrument.m index 147b53c516ae..d37861649d62 100644 --- a/FirebasePerformance/Sources/Instrumentation/UIKit/FPRUIViewControllerInstrument.m +++ b/FirebasePerformance/Sources/Instrumentation/UIKit/FPRUIViewControllerInstrument.m @@ -14,6 +14,7 @@ #import #import +#import #import "FirebasePerformance/Sources/AppActivity/FPRScreenTraceTracker+Private.h" #import "FirebasePerformance/Sources/Common/FPRDiagnostics.h" @@ -69,12 +70,22 @@ void InstrumentViewDidAppear(FPRUIViewControllerInstrument *instrument, // This has to be called on the main thread and so it's done here instead of in // FPRScreenTraceTracker. - // TODO(#13067): Replace keyWindow usage (deprecated in iOS and unavailable in visionOS). #if !defined(TARGET_OS_VISION) || !TARGET_OS_VISION -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - if ([((UIViewController *)_self).view isDescendantOfView:FPRSharedApplication().keyWindow]) { -#pragma clang diagnostic pop + NSArray *windows; + if (@available(iOS 13.0, *)) { + NSArray *scenes = FPRSharedApplication().connectedScenes.allObjects; + windows = [[scenes objectAtIndex:0] windows]; + } else { + windows = FPRSharedApplication().windows; + } + UIWindow *foundKeyWindow; + for (UIWindow *window in windows) { + if (window.isKeyWindow) { + foundKeyWindow = window; + break; + } + } + if (foundKeyWindow && [((UIViewController *)_self).view isDescendantOfView:foundKeyWindow]) { [[FPRScreenTraceTracker sharedInstance] viewControllerDidAppear:_self]; } #endif