Files
youle_app_ios_v2/ylgamehall/Source/Resource/BundleConfig.swift
T

73 lines
3.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// BundleConfig.swift
// ylgamehall
//
// 渠道注入配置:从 Bundle 内的 ChannelConfig.plist 读 11 个 string 值。
// 设计模式与契约见 docs/H5-Native-Implementation-Design.md §7 / ADR-007。
//
// 注:
// - 原有 qiniudomain 字段已于 2026-06-27 移除,七牛 CDN 域名改由
// RemoteConfig 顶层 audio_domain 单一权威源动态下发。
// - 新增 multishare 字段:控制子游戏 sharefriend=1 好友分享的形态
// ("1" = SharePanel 三选一 / "0" = 仅微信直发)。
//
import Foundation
/// 渠道注入配置(11 项),由 `BundleConfig.shared` 在 App 启动时一次性加载,运行期不变。
///
/// 多渠道分发:构建后用 `plutil` 修改 `.app/ChannelConfig.plist` + 重签,
/// 不需要重新 Xcode build。详见 ADR-007。
nonisolated public final class BundleConfig: Sendable {
/// App 启动期默认读 main bundle 的 `ChannelConfig.plist`,业务代码统一通过此单例访问。
public static let shared = BundleConfig()
public let gameId: String
public let channel: String
public let gameDir: String
public let gameStart: String
public let gameConfig: String
public let market: String
public let agent: String
public let appVersion: String
public let other: String
public let appleConfig: String
/// 子游戏内 sharefriend=1 好友分享的形态开关(渠道级):
/// "1" → SharePanel 三选一(微信 / QQ / 抖音,当前默认行为)
/// "0" → 关闭三分享,直接走微信分享(不弹面板)
/// 缺失或其他值视为 "1"(默认开启,兼容旧行为)。
public let multiShare: String
/// 是否启用 SharePanel 三选一。等价 `multiShare != "0"`
/// 空字符串 / 缺失字段视为启用(默认行为)。
public var isMultiShareEnabled: Bool {
multiShare != "0"
}
/// 单测可注入任意 bundle 验证不同 plist fixture。
public init(bundle: Bundle = .main) {
let dict = Self.loadPlist(bundle: bundle)
gameId = dict["gameid"] ?? ""
channel = dict["channel"] ?? ""
gameDir = dict["gamedir"] ?? ""
gameStart = dict["gamestart"] ?? ""
gameConfig = dict["gameconfig"] ?? ""
market = dict["market"] ?? ""
agent = dict["agent"] ?? ""
appVersion = dict["appversion"] ?? ""
other = dict["other"] ?? ""
appleConfig = dict["appleconfig"] ?? ""
multiShare = dict["multishare"] ?? ""
}
private static func loadPlist(bundle: Bundle) -> [String: String] {
guard let url = bundle.url(forResource: "ChannelConfig", withExtension: "plist"),
let data = try? Data(contentsOf: url),
let plist = try? PropertyListSerialization.propertyList(
from: data, format: nil) as? [String: String]
else { return [:] }
return plist
}
}