XuqmGroup-iOSSDK/Sources/XuqmCoreSDK/ConfigFileReader.swift
XuqmGroup 25b80ce9e3 feat(sdk): 将许可证文件替换为初始化配置文件
- 将 license.xuqm 文件替换为 config.xuqm 配置文件
- 实现 ConfigFileReader 来读取和解密配置文件
- 添加 ConfigFileCrypto 用于配置文件加密解密
- 更新 autoInitialize 方法以从配置文件自动初始化
- 移除对 sdk-license 的反射依赖
- 在 HarmonySDK 中实现配置端点动态配置
- 更新 iOS SDK 中的配置文件读取逻辑
- 统一各平台配置文件格式和处理方式
2026-06-02 17:15:49 +08:00

39 行
1.6 KiB
Swift

import Foundation
/// Reads and decrypts the init config file from the app bundle.
/// Looks for xuqm/config.xuqm first, then falls back to any *.xuqmconfig file.
/// This is used by XuqmSDK.autoInitialize() and does NOT depend on XuqmLicenseSDK.
public enum ConfigFileReader {
public static func read() -> ConfigFileData? {
guard let url = Bundle.main.url(forResource: "config", withExtension: "xuqm", subdirectory: "xuqm"),
let encrypted = try? String(contentsOf: url, encoding: .utf8) else {
// Fallback: try any *.xuqmconfig file
if let fallbackURL = findConfigFallback(),
let encrypted = try? String(contentsOf: fallbackURL, encoding: .utf8) {
return parse(encrypted)
}
return nil
}
return parse(encrypted)
}
static func parse(_ encrypted: String) -> ConfigFileData? {
guard let json = try? ConfigFileCrypto.decrypt(encrypted),
let data = json.data(using: .utf8),
let file = try? JSONDecoder().decode(ConfigFileData.self, from: data) else {
return nil
}
return file
}
private static func findConfigFallback() -> URL? {
guard let resourceURL = Bundle.main.resourceURL else { return nil }
let xuqmDir = resourceURL.appendingPathComponent("xuqm")
guard let contents = try? FileManager.default.contentsOfDirectory(at: xuqmDir, includingPropertiesForKeys: nil) else {
return nil
}
return contents.first { $0.pathExtension.lowercased() == "xuqmconfig" }
}
}