Skip to content

Commit

Permalink
Change deprecated keyWindow to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
themiswang committed Nov 7, 2024
1 parent 5366717 commit 0ec7e3d
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#import <TargetConditionals.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIWindowScene.h>

#import "FirebasePerformance/Sources/AppActivity/FPRScreenTraceTracker+Private.h"
#import "FirebasePerformance/Sources/Common/FPRDiagnostics.h"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ec7e3d

Please sign in to comment.