refactor: 更新 EPProgressHUD 和 YUMIMacroUitls.h 以兼容 iOS 13+
主要变更: 1. 在 EPProgressHUD.swift 中引入 keyWindow 的兼容获取方法,替换原有的 UIApplication.shared.keyWindow 调用。 2. 在 YUMIMacroUitls.h 中添加状态栏高度和 keyWindow 的兼容宏定义,确保在 iOS 13+ 中正确获取相关窗口和状态栏信息。 此更新旨在提升代码的兼容性和稳定性,确保在新版本的 iOS 中正常运行。
This commit is contained in:
@@ -13,13 +13,25 @@ import Foundation
|
||||
|
||||
private static var currentHUD: MBProgressHUD?
|
||||
|
||||
/// 获取当前活跃的 window(兼容 iOS 13+)
|
||||
private static var keyWindow: UIWindow? {
|
||||
if #available(iOS 13.0, *) {
|
||||
return UIApplication.shared.connectedScenes
|
||||
.compactMap { $0 as? UIWindowScene }
|
||||
.flatMap { $0.windows }
|
||||
.first { $0.isKeyWindow }
|
||||
} else {
|
||||
return UIApplication.shared.keyWindow
|
||||
}
|
||||
}
|
||||
|
||||
/// 显示上传进度
|
||||
/// - Parameters:
|
||||
/// - uploaded: 已上传数量
|
||||
/// - total: 总数量
|
||||
@objc static func showProgress(_ uploaded: Int, total: Int) {
|
||||
DispatchQueue.main.async {
|
||||
guard let window = UIApplication.shared.keyWindow else { return }
|
||||
guard let window = keyWindow else { return }
|
||||
|
||||
if let hud = currentHUD {
|
||||
// 更新现有 HUD
|
||||
@@ -40,8 +52,7 @@ import Foundation
|
||||
/// 关闭 HUD
|
||||
@objc static func dismiss() {
|
||||
DispatchQueue.main.async {
|
||||
guard let window = UIApplication.shared.keyWindow,
|
||||
let hud = currentHUD else { return }
|
||||
guard let hud = currentHUD else { return }
|
||||
|
||||
hud.hide(animated: true)
|
||||
currentHUD = nil
|
||||
|
Reference in New Issue
Block a user