//说明:测试环境时,如有切换IP的需求,可以打开该宏,同时工程引入Settings.bundle。生产环境请一定注释掉该宏,并删除工程对Settings.bundle的引用。
#define SUPPORT_SettingsBundle_CONFIG_IP
根据identifier这个key对应的值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是测试环境,允许通过Settings.bundle修改测试环境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是生产环境,不允许修改IP");
}
#endif