
新增Package.swift和Package.resolved文件以支持Swift Package管理,创建API相关文件(API.swift、APICaller.swift、APIConstants.swift、APIEndpoints.swift、APIService.swift、APILogger.swift、APIModels.swift、Integration-Guide.md)以实现API请求管理和网络交互功能,增强项目的功能性和可扩展性。同时更新.gitignore以排除构建文件和临时文件。
62 lines
1.4 KiB
Swift
62 lines
1.4 KiB
Swift
enum Environment {
|
||
case development
|
||
case production
|
||
}
|
||
|
||
struct AppConfig {
|
||
static var current: Environment = {
|
||
#if DEBUG
|
||
return .development
|
||
#else
|
||
return .production
|
||
#endif
|
||
}()
|
||
|
||
static var baseURL: String {
|
||
switch current {
|
||
case .development:
|
||
return "http://beta.api.molistar.xyz"
|
||
case .production:
|
||
return "https://api.hfighting.com"
|
||
}
|
||
}
|
||
|
||
// 添加更多环境变量
|
||
static var analyticsKey: String {
|
||
switch current {
|
||
case .development: return "dev_analytics_key"
|
||
case .production: return "prod_analytics_key"
|
||
}
|
||
}
|
||
|
||
// 运行时切换环境(用于测试)
|
||
static func switchEnvironment(to env: Environment) {
|
||
current = env
|
||
}
|
||
|
||
// 添加调试配置
|
||
static var enableNetworkDebug: Bool {
|
||
#if DEBUG
|
||
return true
|
||
#else
|
||
return false
|
||
#endif
|
||
}
|
||
|
||
// 添加服务器信任配置
|
||
static var serverTrustPolicies: [String: ServerTrustEvaluating] {
|
||
#if DEBUG
|
||
return ["beta.api.molistar.xyz": DisabledTrustEvaluator()]
|
||
#else
|
||
return ["api.hfighting.com": PublicKeysTrustEvaluator()]
|
||
#endif
|
||
}
|
||
|
||
static var networkDebugEnabled: Bool {
|
||
#if DEBUG
|
||
return true
|
||
#else
|
||
return false
|
||
#endif
|
||
}
|
||
} |