per-app-vpn - 关于iOS7新特性Per App VPN的问题.
伊谢尔伦
伊谢尔伦 2017-04-17 17:54:07
0
0
620

NEVPNManager *manager = [NEVPNManager sharedManager];

[manager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
    if(error) {
        NSLog(@"Load error: %@", error);
    } else {
        // No errors
        NEVPNProtocolIPSec *protocol = [[NEVPNProtocolIPSec alloc] init];
        protocol.username = @"[Your username]";
        protocol.passwordReference = [KeyChainAccess loadDataForServiceNamed:@"[Your Service Name]"]; //[VPN user password from keychain]
        protocol.serverAddress = @"[Your server address]";
        //protocol.authenticationMethod = NEVPNIKEAuthenticationMethodCertificate;
        protocol.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret;
       // protocol.sharedSecretReference = [VPN server shared secret from keychain];
        protocol.localIdentifier = @"[VPN local identifier]";
        protocol.remoteIdentifier = @"[VPN remote identifier]";
        protocol.useExtendedAuthentication = YES;
        protocol.disconnectOnSleep = NO;
        protocol.identityData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"clientCert" ofType:@"p12"]];
        [manager setProtocol:protocol];
        [manager setOnDemandEnabled:YES];
        [manager setLocalizedDescription:@"[You VPN configuration name]"];
        NSMutableArray *rules = [[NSMutableArray alloc] init];
        NEOnDemandRuleConnect *connectRule = [NEOnDemandRuleConnect new];
        [rules addObject:connectRule];
        [manager setOnDemandRules:rules];
        [manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
            if(error) {
                NSLog(@"Save error: %@", error);
            }
            else {
                NSLog(@"Saved!");
            }
        }];
    }
}];


示范代码如上,配置了几次都不能成功,点了很多头文件进去阅读,但还是理解不够.希望有做过这方面的大哥给点意见.
还有这段代码没读懂,意思是从钥匙串里面取密码吗? 总而言之,希望做过VPN配置的大哥指点一下!!! 万分感激!!!

protocol.passwordReference = [KeyChainAccess loadDataForServiceNamed:@"[Your Service Name]"];

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

Antworte allen(0)
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage