-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c42e58
commit 3813325
Showing
3 changed files
with
24 additions
and
4 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
Sources/HydrogenReporter/Backbone/Extensions/UIApplication+MainScene.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import UIKit | ||
|
||
/// https://stackoverflow.com/a/68989580/14886210 | ||
extension UIApplication { | ||
var mainScene: UIScene? { | ||
return UIApplication.shared.connectedScenes | ||
.first(where: {$0.activationState == .foregroundActive}) | ||
} | ||
|
||
var keyWindow: UIWindow? { | ||
// Get connected scenes | ||
return UIApplication.shared.connectedScenes | ||
// Keep only active scenes, onscreen and visible to the user | ||
.filter { $0.activationState == .foregroundActive } | ||
// Keep only the first `UIWindowScene` | ||
.first(where: { $0 is UIWindowScene }) | ||
// Get its associated windows | ||
.flatMap({ $0 as? UIWindowScene })?.windows | ||
// Finally, keep only the key window | ||
.first(where: \.isKeyWindow) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters