在网络请求之前,进行下系统代理的判断,如果系统开启了代理,则停止后面的网络请求,这样就可以解决数据被抓包问题
- (BOOL) checkProxySetting { NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings()); NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef _Nonnull)([NSURL URLWithString:@"https://www.baidu.com"]), (__bridge CFDictionaryRef _Nonnull)(proxySettings))); NSLog(@"\n%@",proxies); NSDictionary *settings = proxies[0]; NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyHostNameKey]); NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyPortNumberKey]); NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyTypeKey]); if ([[settings objectForKey:(NSString *)kCFProxyTypeKey] isEqualToString:@"kCFProxyTypeNone"]) { NSLog(@"没设置代理"); return NO; } else { NSLog(@"设置了代理"); return YES; } }
微信扫码查看本文
发表评论