per-app-vpn - 关于iOS7新特性Per App VPN的问题.
伊谢尔伦
伊谢尔伦 2017-04-17 17:54:07
[iOS讨论组]

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伐。

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号