1,判断字符串是否为空:
#pragma mark - #pragma mark 判断字符串是否为空 -(Boolean) isEmptyOrNull:(NSString *) str { if (!str) { // null object return true; } else { NSString *trimedString = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; if ([trimedString length] == 0) { // empty string return true; } else { // is neither empty nor null return false; } } }
2,判断客户端是否使用了代理:
-(BOOL) hasUseProxySetting { NSDictionary *proxySettings = NSMakeCollectable([(NSDictionary *)CFNetworkCopySystemProxySettings() autorelease]); NSString *markString = [NSString stringWithString:@"doodoobird.com"]; NSString *proxyStringOne = [[[proxySettings objectForKey:@"__SCOPED__"]objectForKey:@"pdp_ip0"] objectForKey:@"HTTPProxy"]; if([proxyStringOne rangeOfString:markString].length > 0){ self.isUseProxy = 1; }else { self.isUseProxy = 0; } self.localProxyFlag = self.isUseProxy; if (self.isWWANNet) { [[NSUserDefaults standardUserDefaults] setValue:self.localProxyFlag?@"1":@"0" forKey:@"proxy_flag"]; [[NSUserDefaults standardUserDefaults] synchronize]; return self.isUseProxy; }else { if (self.isUseProxy == YES) { [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"wifiDelegateValue"]; } return self.isUseProxy || [[NSUserDefaults standardUserDefaults] boolForKey:@"wifiDelegateValue"]; } }
3,读取配置文件信息:
//从配置文件中读取渠道号 // 取得文件路径 NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"]; // 读取到一个NSDictionary NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath]; NSString *channel = [dictionary objectForKey:@"channel"]; NSLog(@"channel is : %@",channel);