diff --git a/Sources/HydrogenReporter/Backbone/Extensions/UIApplication+MainScene.swift b/Sources/HydrogenReporter/Backbone/Extensions/UIApplication+MainScene.swift new file mode 100644 index 0000000..b0dc74e --- /dev/null +++ b/Sources/HydrogenReporter/Backbone/Extensions/UIApplication+MainScene.swift @@ -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) + } +} + diff --git a/Sources/HydrogenReporter/Views/HydrogenReporter/DebugView.swift b/Sources/HydrogenReporter/Views/HydrogenReporter/DebugView.swift index 6f0e3aa..e8ed5a2 100644 --- a/Sources/HydrogenReporter/Views/HydrogenReporter/DebugView.swift +++ b/Sources/HydrogenReporter/Views/HydrogenReporter/DebugView.swift @@ -203,7 +203,7 @@ struct DebugView: View { @discardableResult func shareLog() throws -> Bool { - guard let source = UIApplication.shared.windows.last?.rootViewController else { + guard let source = UIApplication.shared.keyWindow?.rootViewController else { return false } diff --git a/Sources/HydrogenReporter/Views/HydrogenReporter/StatisticsView.swift b/Sources/HydrogenReporter/Views/HydrogenReporter/StatisticsView.swift index 90b8ddc..75d16d3 100644 --- a/Sources/HydrogenReporter/Views/HydrogenReporter/StatisticsView.swift +++ b/Sources/HydrogenReporter/Views/HydrogenReporter/StatisticsView.swift @@ -44,11 +44,8 @@ struct StatisticsView: View { RowView(label: "Device Name", data: UIDevice.modelName, onTapData: UIDevice.current.model) RowView(label: "System Bane", data: UIDevice.current.systemName) RowView(label: "System Version", data: UIDevice.current.systemVersion) - #if os(xrOS) - #else RowView(label: "Orientation", data: parseOrientation(UIDevice.current.orientation)) RowView(label: "In Valid Orientation", data: "\(UIDevice.current.orientation.isValidInterfaceOrientation)") - #endif RowView(label: "Multitasking Supported", data: "\(UIDevice.current.isMultitaskingSupported)") RowView(label: "Interface Idiom", data: parseInterfaceIdiom(UIDevice.current.userInterfaceIdiom)) }