Skip to content

Commit 0ec7e3d

Browse files
committed
Change deprecated keyWindow to new API
1 parent 5366717 commit 0ec7e3d

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

FirebasePerformance/Sources/Instrumentation/UIKit/FPRUIViewControllerInstrument.m

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#import <TargetConditionals.h>
1616
#import <UIKit/UIKit.h>
17+
#import <UIKit/UIWindowScene.h>
1718

1819
#import "FirebasePerformance/Sources/AppActivity/FPRScreenTraceTracker+Private.h"
1920
#import "FirebasePerformance/Sources/Common/FPRDiagnostics.h"
@@ -69,12 +70,22 @@ void InstrumentViewDidAppear(FPRUIViewControllerInstrument *instrument,
6970

7071
// This has to be called on the main thread and so it's done here instead of in
7172
// FPRScreenTraceTracker.
72-
// TODO(#13067): Replace keyWindow usage (deprecated in iOS and unavailable in visionOS).
7373
#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
74+
NSArray *windows;
75+
if (@available(iOS 13.0, *)) {
76+
NSArray *scenes = FPRSharedApplication().connectedScenes.allObjects;
77+
windows = [[scenes objectAtIndex:0] windows];
78+
} else {
79+
windows = FPRSharedApplication().windows;
80+
}
81+
UIWindow *foundKeyWindow;
82+
for (UIWindow *window in windows) {
83+
if (window.isKeyWindow) {
84+
foundKeyWindow = window;
85+
break;
86+
}
87+
}
88+
if (foundKeyWindow && [((UIViewController *)_self).view isDescendantOfView:foundKeyWindow]) {
7889
[[FPRScreenTraceTracker sharedInstance] viewControllerDidAppear:_self];
7990
}
8091
#endif

0 commit comments

Comments
 (0)