this is my setting
NEIPv4Settings *ipv4Settings = [[NEIPv4Settings alloc] initWithAddresses:@[@"127.0.0.1"] subnetMasks:@[@"255.255.255.0"]];
ipv4Settings.includedRoutes = @[[NEIPv4Route defaultRoute]];
/**ip4 = @[@"1.1.8.0/24",@"1.2.4.0/24",...] ,ip4.count about four thousand.
The source is connected below:
[ipv4](https://developer.apple.com/forums/content/attachment/29112ae2-f16b-4ac3-9f5a-41551d194c05)
*/
NSArray *ip4 = [self returnChinaIPV4];
NSMutableArray *excludedRoutes= [[NSMutableArray alloc]init];
NSDictionary *subnetMaskDic = [self returnSubnetMask];
for (NSString *str in ip4) {
NSArray *temp = [str componentsSeparatedByString:@"/"];
NSString *fist = [NSString stringWithFormat:@"%@",[temp firstObject]];
NSString *last = [NSString stringWithFormat:@"%@",[temp lastObject]];
NSString *subnetMask = [subnetMaskDic objectForKey:last];
NEIPv4Route *route = [[NEIPv4Route alloc]initWithDestinationAddress:fist subnetMask:subnetMask];
[excludedRoutes addObject:route];
}
//excludedRoutes not effective
ipv4Settings.excludedRoutes = excludedRoutes;
NEProxySettings* proxySettings = [[NEProxySettings alloc] init];
NSInteger proxyServerPort = [ProxyManager sharedManager].httpProxyPort;
NSString *proxyServerName = @"127.0.0.1";
proxySettings.HTTPEnabled = YES;
proxySettings.HTTPServer = [[NEProxyServer alloc] initWithAddress:proxyServerName port:proxyServerPort];
proxySettings.HTTPSEnabled = YES;
proxySettings.HTTPSServer = [[NEProxyServer alloc] initWithAddress:proxyServerName port:proxyServerPort];
proxySettings.excludeSimpleHostnames = YES;
NEPacketTunnelNetworkSettings *settings = [[NEPacketTunnelNetworkSettings alloc] initWithTunnelRemoteAddress:@"127.0.0.1"];
settings.MTU = @(1600);
settings.IPv4Settings = ipv4Settings;
settings.proxySettings = proxySettings;
[self setTunnelNetworkSettings:settings completionHandler:^(NSError * _Nullable error) {
if (error) {
if (completionHandler) {
completionHandler(error);
}
}else{
if (completionHandler) {
completionHandler(nil);
}
}
}];