三 Flavor(Shijiaobao / Clinical / Yiwangxin)iOS 项目
架构
- Shared/ 全部共用层:AppHomeView、WebMessageHandler(JSBridge)、DevUrlSettings
- *Flavor/ 各 flavor 入口:AppConfig、*App(@main)、AppDelegate(Yiwangxin 含 Push)
- project.yml + xcodegen 管理项目结构
SDK 集成
- 引用 Gitea SPM 包(branch: main,SNAPSHOT 开发模式)
- sdk.properties 追踪当前 SDK_REF,scripts/use-sdk.sh 支持 main/local/x.y.z 一键切换
- 含各 flavor xuqm/*.xuqmconfig 配置文件
JSBridge 协议
- window.webkit.messageHandlers.SZYX_APP.postMessage(json)
- 回调 window.SZYX_YWX_WebViewBridge.onMessage(json)
- 实现 setTitle/getDeviceInfo/login/setUserInfo/getAppVersion/checkUpdate
setStorage/getStorage/removeStorage/clearStorage/setOrientation/apiError
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
78 行
2.4 KiB
Swift
78 行
2.4 KiB
Swift
import SwiftUI
|
||
|
||
private let kDevUrlKey = "dev_custom_start_url"
|
||
|
||
/// Debug-only URL switcher. Mirrors Android's DevUrlSettingsActivity.
|
||
/// Production builds should never show or use this.
|
||
enum DevUrlSettings {
|
||
static var effectiveStartUrl: String? {
|
||
#if DEBUG
|
||
return UserDefaults.standard.string(forKey: kDevUrlKey)?.nonEmpty
|
||
#else
|
||
return nil
|
||
#endif
|
||
}
|
||
|
||
static func save(_ url: String) {
|
||
UserDefaults.standard.set(url.trimmingCharacters(in: .whitespaces), forKey: kDevUrlKey)
|
||
}
|
||
|
||
static func clear() {
|
||
UserDefaults.standard.removeObject(forKey: kDevUrlKey)
|
||
}
|
||
}
|
||
|
||
#if DEBUG
|
||
struct DevUrlSettingsSheet: View {
|
||
@Environment(\.dismiss) private var dismiss
|
||
@State private var input: String = DevUrlSettings.effectiveStartUrl ?? ""
|
||
|
||
var body: some View {
|
||
NavigationStack {
|
||
Form {
|
||
Section {
|
||
TextField("自定义 URL(留空使用默认)", text: $input, axis: .vertical)
|
||
.keyboardType(.URL)
|
||
.autocorrectionDisabled()
|
||
.textInputAutocapitalization(.never)
|
||
.lineLimit(4)
|
||
} header: {
|
||
Text("调试用后端地址")
|
||
} footer: {
|
||
Text("设置后重启 App 生效。留空则使用 AppConfig.startUrl。")
|
||
}
|
||
|
||
Section {
|
||
Button("使用默认地址") {
|
||
input = ""
|
||
}
|
||
.foregroundStyle(.secondary)
|
||
}
|
||
}
|
||
.navigationTitle("开发环境设置")
|
||
.navigationBarTitleDisplayMode(.inline)
|
||
.toolbar {
|
||
ToolbarItem(placement: .confirmationAction) {
|
||
Button("保存") {
|
||
let trimmed = input.trimmingCharacters(in: .whitespaces)
|
||
if trimmed.isEmpty {
|
||
DevUrlSettings.clear()
|
||
} else {
|
||
DevUrlSettings.save(trimmed)
|
||
}
|
||
dismiss()
|
||
}
|
||
}
|
||
ToolbarItem(placement: .cancellationAction) {
|
||
Button("取消") { dismiss() }
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endif
|
||
|
||
private extension String {
|
||
var nonEmpty: String? { isEmpty ? nil : self }
|
||
}
|