001project_wildgrowth/ios/WildGrowth/WildGrowth/WildGrowthApp.swift

46 lines
1.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
import Kingfisher
@main
struct WildGrowthApp: App {
// UserManager
@StateObject private var userManager = UserManager.shared
init() {
// 🔥 Kingfisher
configureKingfisher()
// V1.0 +
AnalyticsManager.shared.track("app_launch")
}
var body: some Scene {
WindowGroup {
// SplashView
SplashView(isLoggedIn: $userManager.isLoggedIn)
.environmentObject(userManager)
}
}
// MARK: - Kingfisher
private func configureKingfisher() {
// 1.
let cache = ImageCache.default
cache.memoryStorage.config.totalCostLimit = 150 * 1024 * 1024 // 150MB
cache.memoryStorage.config.countLimit = 150 // 150
cache.memoryStorage.config.expiration = .seconds(3600) // 1
cache.diskStorage.config.sizeLimit = 1000 * 1024 * 1024 // 1GB
cache.diskStorage.config.expiration = .days(7) // 7
// 2.
let downloader = ImageDownloader.default
downloader.downloadTimeout = 20.0 // 20
//
downloader.sessionConfiguration.httpMaximumConnectionsPerHost = 6 // 6
// 3.
cache.cleanExpiredCache()
print("✅ Kingfisher 配置完成:内存缓存 150MB磁盘缓存 1GB并发连接 6")
}
}