jsdw_ios/QuickLocation/Manager/URL/URLManager.swift

100 lines
2.4 KiB
Swift

//
// URLManager.swift
// SHECommunity
//
// Created by on 2024/11/26.
//
import Foundation
import SwiftyUserDefaults
import RxSwift
extension DefaultsKeys {
// 0: 1:
var apiEnvKey: DefaultsKey<Int> { .init("ApiEnvKey", defaultValue: -99) }
//
var apiServerURL: DefaultsKey<String> { .init("ApiServerURL", defaultValue: "") }
}
@objcMembers class URLManager: NSObject {
static let shared = URLManager()
// -1: UAT 0: 1:
var apiEnv: Int = 0
///
var apiServerURL: String = "" {
didSet {
AppNetworkConfig.shared.baseURL = apiServerURL
}
}
/// OpenIM SDK
var openIM_API = ""
var openIM_WS = ""
///
var userAgreementUrl: String { "https://sd.zuom8.cn/Agreement.html" }
///
var privacyPolicyUrl: String { "https://sd.zuom8.cn/Privacy.html" }
///
var cancellationNoticeUrl: String { "https://h5.yiwen618.com.cn/yiwen_h5_logoff.html" }
private override init() {
super.init()
self.setupNetworkMode()
}
func setupNetworkMode() {
#if DEBUG
setupApiEnv(1)
openIM_API = "https://imapi.zuom8.cn"
openIM_WS = "ws://imws.zuom8.cn"
#elseif AdHoc
setupApiEnv(-1)
openIM_API = "http://38.207.176.65:10002"
openIM_WS = "ws://38.207.176.65:10010"
#else
setupApiEnv(1)
openIM_API = "http://38.207.176.65:10002"
openIM_WS = "ws://38.207.176.65:10010"
#endif
}
private func setupApiEnv(_ env: Int) {
// env
if Defaults[\.apiEnvKey] != -99 {
apiEnv = Defaults[\.apiEnvKey]
}
else {
apiEnv = env
}
// api
if Defaults[\.apiServerURL].isEmpty {
apiServerURL = apiServerURL(apiEnv)
} else {
apiServerURL = Defaults[\.apiServerURL]
}
}
// MARK: -
func apiServerURL(_ env: Int) -> String {
switch env {
case 1: //
return "https://jsapi.zuom8.cn/"
case -1: // UAT
return "https://jsapi.zuom8.cn/"
default: // SIT
return "https://jsapi.zuom8.cn/"
}
}
// MARK: -
func uploadServerURL() -> String {
//#if DEBUG
// return ""
//#else
return ""
//#endif
}
}