Skip to content

Commit ae87f84

Browse files
refactor firstKeyWindowForConnectedScenes
1 parent b767f99 commit ae87f84

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

iOS_SDK/OneSignalSDK/Source/UIApplication+OneSignal.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,20 @@ + (BOOL)isAppUsingUIScene {
5252

5353
+ (UIWindow *)firstKeyWindowForConnectedScenes {
5454
if (@available(iOS 13.0, *)) {
55+
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
56+
if ([scene isKindOfClass:[UIWindowScene class]] &&
57+
scene.activationState == UISceneActivationStateForegroundActive) {
58+
for (UIWindow *window in ((UIWindowScene *)scene).windows) {
59+
if (window.isKeyWindow) {
60+
return window;
61+
}
62+
}
63+
}
64+
}
65+
// fall back to any connected scene if none is foreground-active yet
5566
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
5667
if ([scene isKindOfClass:[UIWindowScene class]]) {
57-
UIWindowScene *windowScene = (UIWindowScene *)scene;
58-
for (UIWindow *window in windowScene.windows) {
68+
for (UIWindow *window in ((UIWindowScene *)scene).windows) {
5969
if (window.isKeyWindow) {
6070
return window;
6171
}

0 commit comments

Comments
 (0)