//說明:測試環(huán)境時饮怯,如有切換IP的需求字币,可以打開該宏,同時工程引入Settings.bundle辅斟。生產(chǎn)環(huán)境請一定注釋掉該宏,并刪除工程對Settings.bundle的引用郭怪。
#define SUPPORT_SettingsBundle_CONFIG_IP
根據(jù)identifier這個key對應(yīng)的值offline_preference去取 ?offline的值
#define SUPPORT_SettingsBundle_CONFIG_IP
#ifdef SUPPORT_SettingsBundle_CONFIG_IP
NSURL *settingURL = [[NSBundle mainBundle] URLForResource:@"Settings" withExtension:@"bundle"];
if(settingURL!=nil)
{
//如果當前SERVER_BACKEND_URL是測試環(huán)境,允許通過Settings.bundle修改測試環(huán)境IP
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfURL:[settingURL URLByAppendingPathComponent:@"Root.plist"]];
NSMutableDictionary *appDefaults = [NSMutableDictionary dictionary];
NSLog(@"1111:%@",dict);
NSString *ip,*port;
for (NSDictionary *item in dict[@"PreferenceSpecifiers"]) {
if (item[@"Key"] && item[@"DefaultValue"]) {
[appDefaults setObject:item[@"DefaultValue"] forKey:item[@"Key"]];
}
}
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];
ip = [[NSUserDefaults standardUserDefaults] objectForKey:@"ip_preference"];
BOOL offline = [[[NSUserDefaults standardUserDefaults] objectForKey:@"offline_preference"] boolValue];
NSString *offline = [[NSUserDefaults standardUserDefaults] objectForKey:@"offline_preference"];
NSLog(@"ip:%@",ip);
NSLog(@"port:%@",port);
NSLog(@"offline:%@",offline);
//? ? ? ? [Context sharedInstance].offLine = NO;//[[[NSUserDefaults standardUserDefaults] objectForKey:@"offline_preference"] boolValue];
//? ? ? ? //離線
//? ? ? ? if ([Context sharedInstance].offLine) {
//? ? ? ? ? ? server_backend_url = @"";
//? ? ? ? }
//? ? ? ? //非離線 讀取ip刊橘、port
//? ? ? ? else if (ip && port) {
//? ? ? ? ? ? server_backend_url = [ip stringByAppendingFormat:@":%@",port];
//? ? ? ? }else{
//? ? ? ? ? ? server_backend_url = SERVER_BACKEND_URL;
//? ? ? ? }
}
else
{
//沒有配置Settings.bundle
NSLog(@"Could not find Settings.bundle, or 當前SERVER_BACKEND_URL是生產(chǎn)環(huán)境鄙才,不允許修改IP");
}
#endif