
- 在Info.plist中新增API签名密钥配置。 - 将Splash视图替换为SplashV2,优化启动逻辑和用户体验。 - 更新API请求中的User-Agent逻辑,使用UserAgentProvider提供的动态值。 - 在APILogger中添加敏感信息脱敏处理,增强安全性。 - 新增CreateFeedPage视图,支持用户发布动态功能。 - 更新MainPage和Splash视图的导航逻辑,整合统一的AppRoute管理。 - 移除冗余的SplashFeature视图,提升代码整洁性和可维护性。
34 lines
1.1 KiB
Swift
34 lines
1.1 KiB
Swift
import Foundation
|
||
import Network
|
||
|
||
/// 监听系统网络状态并缓存最近结果
|
||
/// WiFi=2, 蜂窝=1, 未知/无网络=0(与现有代码语义对齐)
|
||
final class NetworkMonitor: @unchecked Sendable {
|
||
static let shared = NetworkMonitor()
|
||
private let monitor = NWPathMonitor()
|
||
private let queue = DispatchQueue(label: "com.yana.network.monitor")
|
||
private var _currentType: Int = 2 // 默认与历史保持一致
|
||
var currentType: Int { _currentType }
|
||
private init() {
|
||
monitor.pathUpdateHandler = { [weak self] path in
|
||
guard let self = self else { return }
|
||
let type: Int
|
||
if path.status == .satisfied {
|
||
if path.usesInterfaceType(.wifi) { type = 2 }
|
||
else if path.usesInterfaceType(.cellular) { type = 1 }
|
||
else { type = 0 }
|
||
} else {
|
||
type = 0
|
||
}
|
||
// 更新缓存(主线程或任一队列均可,这里选择主线程与 UI 一致)
|
||
DispatchQueue.main.async { [weak self] in
|
||
self?._currentType = type
|
||
}
|
||
}
|
||
monitor.start(queue: queue)
|
||
}
|
||
}
|
||
|
||
|
||
|