
- 在Package.swift中注释掉旧的swift-composable-architecture依赖,并添加swift-case-paths依赖。 - 在Podfile中将iOS平台版本更新至16.0,并移除QCloudCOSXML/Transfer依赖,改为使用QCloudCOSXML。 - 更新Podfile.lock以反映依赖变更,确保项目依赖的准确性。 - 新增架构分析需求文档,明确项目架构评估和改进建议。 - 在多个文件中实现async/await语法,提升异步操作的可读性和性能。 - 更新日志输出方法,确保在调试模式下提供一致的调试信息。 - 优化多个视图组件,提升用户体验和代码可维护性。
74 lines
2.6 KiB
Swift
74 lines
2.6 KiB
Swift
import Foundation
|
||
import ComposableArchitecture
|
||
|
||
@Reducer
|
||
struct SplashFeature {
|
||
@ObservableState
|
||
struct State: Equatable {
|
||
var isLoading = true
|
||
var shouldShowMainApp = false
|
||
var authenticationStatus: UserInfoManager.AuthenticationStatus = .notFound
|
||
var isCheckingAuthentication = false
|
||
}
|
||
|
||
enum Action: Equatable {
|
||
case onAppear
|
||
case splashFinished
|
||
case checkAuthentication
|
||
case authenticationChecked(UserInfoManager.AuthenticationStatus)
|
||
}
|
||
|
||
var body: some ReducerOf<Self> {
|
||
Reduce { state, action in
|
||
switch action {
|
||
case .onAppear:
|
||
state.isLoading = true
|
||
state.shouldShowMainApp = false
|
||
state.authenticationStatus = .notFound
|
||
state.isCheckingAuthentication = false
|
||
|
||
// 1秒延迟后显示主应用 (iOS 15.5+ 兼容)
|
||
return .run { send in
|
||
try await Task.sleep(nanoseconds: 1_000_000_000) // 1秒 = 1,000,000,000 纳秒
|
||
await send(.splashFinished)
|
||
}
|
||
case .splashFinished:
|
||
state.isLoading = false
|
||
state.shouldShowMainApp = true
|
||
|
||
// Splash 完成后,开始检查认证状态
|
||
return .send(.checkAuthentication)
|
||
|
||
case .checkAuthentication:
|
||
state.isCheckingAuthentication = true
|
||
|
||
// 异步检查认证状态
|
||
return .run { send in
|
||
let authStatus = await UserInfoManager.checkAuthenticationStatus()
|
||
await send(.authenticationChecked(authStatus))
|
||
}
|
||
|
||
case let .authenticationChecked(status):
|
||
#if DEBUG
|
||
debugInfoSync("🔑 需要手动登录")
|
||
NotificationCenter.default.post(name: .autoLoginFailed, object: nil)
|
||
return .none
|
||
#endif
|
||
state.isCheckingAuthentication = false
|
||
state.authenticationStatus = status
|
||
|
||
// 根据认证状态发送相应的导航通知
|
||
if status.canAutoLogin {
|
||
debugInfoSync("🎉 自动登录成功,进入主页")
|
||
NotificationCenter.default.post(name: .autoLoginSuccess, object: nil)
|
||
} else {
|
||
debugInfoSync("🔑 需要手动登录")
|
||
NotificationCenter.default.post(name: .autoLoginFailed, object: nil)
|
||
}
|
||
|
||
return .none
|
||
}
|
||
}
|
||
}
|
||
}
|