iOS, NEProxySettings doesn’t work,after I use NEVPNManager to develop VPN

[ad_1]

I take advantage of NEVPNManager, I had related success, it really works properly.However After I need to restrict the usage of proxies for some domains, comparable to my very own App. I take advantage of NEProxySettings, Nevertheless it did not work, I do not know why.If anybody will help me, I actually admire it. Let’s suppose my server area is “www.xxx.com”. Right here is my code:

[self.vpnManager loadFromPreferencesWithCompletionHandler:^(NSError * _Nullable error) {
    if (error) {
        PSLog(@"%@",error);
        return;
    }
    NEVPNProtocolIKEv2 *vpnProtocollIKEv2 = (NEVPNProtocolIKEv2 *)self.vpnManager.protocolConfiguration;
    vpnProtocollIKEv2 = [[NEVPNProtocolIKEv2 alloc] init];
    vpnProtocollIKEv2.serverAddress = serviceName;        
    
    NEVPNIKEAuthenticationMethod authenticationMethod = [self authenticationMethod:data.authenticationMethod];
    vpnProtocollIKEv2.authenticationMethod = authenticationMethod;
    
    if (authenticationMethod == NEVPNIKEAuthenticationMethodCertificate) {
        vpnProtocollIKEv2.identityData = [[NSData alloc] initWithBase64EncodedString:p12Base64 choices:NSDataBase64DecodingIgnoreUnknownCharacters];
        vpnProtocollIKEv2.identityDataPassword = certificatePassword;
    }
    NEProxySettings *proxySettings = [[NEProxySettings alloc] init];
    proxySettings.autoProxyConfigurationEnabled = NO;
    proxySettings.excludeSimpleHostnames = YES;
    proxySettings.HTTPEnabled = YES;
    proxySettings.HTTPSEnabled = YES;
    proxySettings.exceptionList = @[@"www.xxx.com",@"*.www.xxx.com"];
    vpnProtocollIKEv2.proxySettings = proxySettings;
            
    vpnProtocollIKEv2.remoteIdentifier = remoteId;

    vpnProtocollIKEv2.localIdentifier = localId;

    vpnProtocollIKEv2.disconnectOnSleep = NO;
    
    self.vpnManager.protocolConfiguration = vpnProtocollIKEv2;
    
    [self.vpnManager saveToPreferencesWithCompletionHandler:^(NSError * _Nullable error) {
        if (error) {
            PSLog(@"%@",error);
            }
            return;
        }
        [self startVPNConnect];
    }];
}];

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *