import Foundation import UIKit @MainActor struct DeviceContext: Sendable { let languageCode: String let osName: String let osVersion: String let deviceModel: String let deviceId: String let appName: String let appVersion: String let channel: String let screenScale: String static let shared: DeviceContext = { // 仅在主线程读取一次 UIKit/Bundle 信息 let language = Locale.current.language.languageCode?.identifier ?? "en" let osName = "iOS" let osVersion = UIDevice.current.systemVersion let deviceModel = UIDevice.current.model let deviceId = UIDevice.current.identifierForVendor?.uuidString ?? UUID().uuidString let appName = Bundle.main.infoDictionary?["CFBundleName"] as? String ?? "eparty" let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0" #if DEBUG let channel = "molistar_enterprise" #else let channel = "appstore" #endif let scale = String(format: "%.2f", Double(UIScreen.main.scale)) return DeviceContext( languageCode: language, osName: osName, osVersion: osVersion, deviceModel: deviceModel, deviceId: deviceId, appName: appName, appVersion: appVersion, channel: channel, screenScale: scale ) }() } enum UserAgentProvider { @MainActor static func userAgent() -> String { let ctx = DeviceContext.shared return "\(ctx.appName)/\(ctx.appVersion) (\(ctx.deviceModel); \(ctx.osName) \(ctx.osVersion); Scale/\(ctx.screenScale))" } }