How to implement VPN(Packet Tunnel Provider) some traffic in that app go over the VPN, and other traffic to go directly to the internet.

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);
       }
     }
   }];

First thing I would do here is tear down a lot of these settings and try to get one set of NEIPv4Settings and NEIPv4Route working. Then, after that is working, try adding in more destination routes for your split tunnel. Also note, I would remove all of your NEProxySettings here unless you have a legitimate business use-case for using these settings inside your packet tunnel.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
How to implement VPN(Packet Tunnel Provider) some traffic in that app go over the VPN, and other traffic to go directly to the internet.
 
 
Q