8000 Change deprecated keyWindow to new API · firebase/firebase-ios-sdk@36530cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 36530cd

Browse files
committed
Change deprecated keyWindow to new API
1 parent 5366717 commit 36530cd

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

FirebasePerformance/Sources/Instrumentation/UIKit/FPRUIViewControllerInstrument.m

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,22 @@ 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;
74+
if (@available(iOS 13.0, *)) {
75+
NSArray *scenes = FPRSharedApplication().connectedScenes.allObjects;
76+
windows = [[scenes objectAtIndex:0] windows];
77+
} else {
78+
windows = FPRSharedApplication().windows;
79+
}
80+
UIWindow *foundKeyWindow;
81+
for (UIWindow *window in windows) {
82+
if (window.isKeyWindow) {
83+
foundKeyWindow = window;
84+
break;
85+
}
86+
}
87+
if (foundKeyWindow && [((UIViewController *)_self).view isDescendantOfView:foundKeyWindow]) {
7888
[[FPRScreenTraceTracker sharedInstance] viewControllerDidAppear:_self];
7989
}
8090
#endif

0 commit comments

Comments
 (0)
0