diff --git a/Sources/HLSRecorder.swift b/Sources/HLSRecorder.swift index bb8e2aa..53741ab 100644 --- a/Sources/HLSRecorder.swift +++ b/Sources/HLSRecorder.swift @@ -354,11 +354,16 @@ final class HLSRecorder: ObservableObject { return } - // 找最顶层可见的 VC(遍历所有 window) + // 找最顶层可见的 VC:先用 keyWindow,再 fallback 到任意 window var topVC: UIViewController? - for window in windowScene.windows where window.isKeyWindow { - topVC = window.rootViewController - break + if let keyWindow = windowScene.keyWindow { + topVC = keyWindow.rootViewController + } + if topVC == nil { + for window in windowScene.windows where !window.isHidden && window.bounds.size != .zero { + topVC = window.rootViewController + if topVC != nil { break } + } } if topVC == nil { topVC = windowScene.windows.first?.rootViewController