Files
waf-platform/HttpDNSSDK/sdk/ios/NewHttpDNSTestDemo/DemoConfigLoader.m
2026-03-05 16:59:19 +08:00

82 lines
2.3 KiB
Objective-C

//
// DemoConfigLoader.m
// TrustHttpDNSTestDemo
//
// @author Created by Claude Code on 2025-10-05
//
#import "DemoConfigLoader.h"
@implementation DemoConfigLoader {
NSString *_appId;
NSString *_apiUrl; // Unified API URL
NSString *_signSecret;
NSString *_serviceDomain;
BOOL _hasValidConfig;
}
+ (instancetype)shared {
static DemoConfigLoader *loader;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
loader = [[DemoConfigLoader alloc] init];
});
return loader;
}
- (instancetype)init {
if (self = [super init]) {
[self loadConfig];
}
return self;
}
// 澶嶆潅閫昏緫锛氶厤缃姞杞介『搴忎负 Bundle > 鐜鍙橀噺锛涘苟瀵?accountID 杩涜鏈夋晥鎬ф牎楠?
- (void)loadConfig {
_appId = @"";
_apiUrl = @"";
_signSecret = @"";
_serviceDomain = @"";
_hasValidConfig = NO;
NSDictionary *bundleDict = nil;
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"DemoConfig" ofType:@"plist"];
if (plistPath.length > 0) {
bundleDict = [NSDictionary dictionaryWithContentsOfFile:plistPath];
}
NSDictionary *env = [[NSProcessInfo processInfo] environment];
NSString *appId = bundleDict[@"appId"] ?: @"";
NSString *apiUrl = bundleDict[@"apiUrl"] ?: @"";
NSString *signSecret = bundleDict[@"signSecret"] ?: @"";
NSString *serviceDomain = bundleDict[@"serviceDomain"] ?: @"";
NSString *envAppId = env[@"HTTPDNS_APP_ID"];
NSString *envApiUrl = env[@"HTTPDNS_API_URL"];
NSString *envSignSecret = env[@"HTTPDNS_SIGN_SECRET"];
NSString *envServiceDomain = env[@"HTTPDNS_SERVICE_DOMAIN"];
if (envAppId.length > 0) appId = envAppId;
if (envApiUrl.length > 0) apiUrl = envApiUrl;
if (envSignSecret.length > 0) signSecret = envSignSecret;
if (envServiceDomain.length > 0) serviceDomain = envServiceDomain;
if (appId.length > 0 && apiUrl.length > 0 && serviceDomain.length > 0) {
_appId = appId;
_apiUrl = apiUrl;
_signSecret = signSecret;
_serviceDomain = serviceDomain;
_hasValidConfig = YES;
}
}
- (NSString *)appId { return _appId; }
- (NSString *)apiUrl { return _apiUrl; }
- (NSString *)signSecret { return _signSecret; }
- (NSString *)serviceDomain { return _serviceDomain; }
- (BOOL)hasValidConfig { return _hasValidConfig; }
@end