98b7600797
对标安卓正式版、对接 app-server(8770)的 SwiftUI 客户端。iOS 无障碍受限、无比价核心,做自成一体:美团 CPS 导购 + 福利(签到/任务/金币)+ 查看(比价记录/省钱战绩)。 功能完整 M0-M5:脚手架、短信登录(JWT+Keychain+401 自动刷新)、首页券 feed 导购、比价记录+省钱战绩、福利、我的(资料/反馈/设置/注销)。 单 target、0 三方依赖、XcodeGen 生成工程;Debug/Release 双 plist 分流 ATS。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
28 lines
1.2 KiB
Swift
28 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
/// 后端地址。debug 连本地/局域网(可被环境变量 SHAGUA_API_BASE_URL 覆盖,真机联调用),
|
|
/// release 连线上。对齐安卓 BuildConfig.BASE_URL 的 debug/release 切换。
|
|
enum AppConfig {
|
|
static let apiBaseURL: URL = {
|
|
#if DEBUG
|
|
if let raw = ProcessInfo.processInfo.environment["SHAGUA_API_BASE_URL"],
|
|
let url = URL(string: raw) {
|
|
return url
|
|
}
|
|
// 真机/模拟器都连开发机的局域网 IP(真机用 127.0.0.1 会连到手机自己,连不上后端)。
|
|
// 换了 WiFi 网段后 IP 会变,用 `ipconfig getifaddr en0` 重查并改这里(或用上面的环境变量覆盖)。
|
|
return URL(string: "http://192.168.0.119:8770")!
|
|
#else
|
|
return URL(string: "https://app-api.shaguabijia.com")!
|
|
#endif
|
|
}()
|
|
|
|
/// 后端相对媒体路径(/media/...)拼成完整 URL,用于展示头像/反馈截图。
|
|
static func mediaURL(_ path: String?) -> URL? {
|
|
guard let path, !path.isEmpty else { return nil }
|
|
if path.hasPrefix("http") { return URL(string: path) }
|
|
let sep = path.hasPrefix("/") ? "" : "/"
|
|
return URL(string: apiBaseURL.absoluteString + sep + path)
|
|
}
|
|
}
|