【问题标题】:iOS 8 VPN - Network Extension - error in __connection_block_invoke_2iOS 8 VPN - 网络扩展 - __connection_block_invoke_2 中的错误
【发布时间】:2015-10-26 10:43:29
【问题描述】:

我正在使用下面的代码来配置 VPN

- (void)setupConfiguration
{
    NEVPNManager *manager = [NEVPNManager sharedManager];
    int status = manager.connection.status;

    if (status == NEVPNStatusConnected) {
        [manager.connection stopVPNTunnel];
    }
    else
    {
        [manager loadFromPreferencesWithCompletionHandler:^(NSError *error)
        {
            if (error) {
                NSLog(@"Load config failed [%@]", error.localizedDescription);
                return;
            }

            NEVPNProtocolIPSec *p = (NEVPNProtocolIPSec *)manager.protocol;
            if (!p) {
                p = [[NEVPNProtocolIPSec alloc] init];
            }

            NSString *username = [Username];
            NSString *url = @"Server URL";
            p.username = username;
            p.serverAddress = url;

            p.passwordReference = [Password from Keychain];
            p.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret;
            p.sharedSecretReference = [Shared secret from Keychain];
            //p.localIdentifier = @"";
            //p.remoteIdentifier = @"";

            p.disconnectOnSleep = NO;
            p.useExtendedAuthentication = YES;

            [manager setProtocol:p];
            [manager setOnDemandEnabled:NO];
            [manager setLocalizedDescription:@"VIT VPN"];
            NSLog(@"Connection desciption: %@", manager.localizedDescription);
            NSLog(@"VPN status:  %li", (long)manager.connection.status);

            [manager saveToPreferencesWithCompletionHandler:^(NSError *error) {
                if(error) {
                    NSLog(@"Save error: %@", error);
                } else {
                    NSLog(@"Saved!");
                }
            }];
        }];
    }
}

我在viewDidLoad 上调用此方法。
当用户在完成配置文件安装后从设备 VPN 设置导航到我们的应用程序时,我在日志中收到此错误 - "error in __connection_block_invoke_2: Connection interrupted"。之后,当我尝试连接到 VPN 服务器时,什么也没有发生。
谁能帮我解决这个问题,为什么我会收到这个错误?

注意:- 我已按照以下教程进行操作:
1.http://ramezanpour.net/post/2014/08/03/configure-and-manage-vpn-connections-programmatically-in-ios-8/
2. https://disqus.com/home/discussion/ramezanpour/configure_and_manage_vpn_connections_programmatically_in_ios_8/newest/

【问题讨论】:

    标签: objective-c ios8 vpn


    【解决方案1】:

    试试这个

    // init VPN manager
    self->vpnManager = [NEVPNManager sharedManager];
    
    // load config from perference
    [vpnManager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
    
    
    
    
    
    
        if (error) {
            NSLog(@"Load config failed [%@]", error.localizedDescription);
            return;
        }
    
        NEVPNProtocolIPSec *p = vpnManager.protocolConfiguration;
    
        if (p) {
            // Protocol exists.
            // If you don't want to edit it, just return here.
        } else {
            // create a new one.
            p = [[NEVPNProtocolIPSec alloc] init];
        }
    
        // config IPSec protocol
        p.username = @"abcde";
    
        p.serverAddress = @"***.***.**.**"; // Your server address
    
    
    
    
        //        p.sharedSecretReference = @"vpnvip";
        // Get password persistent reference from keychain
        // If password doesn't exist in keychain, should create it beforehand.
        [self createKeychainValue:@"aaaaaa" forIdentifier:@"VPN_PASSWORD"];
        p.passwordReference = [self searchKeychainCopyMatching:@"VPN_PASSWORD"];
        //        p.identityDataPassword = @"qwerty";
        // PSK
        p.authenticationMethod = NEVPNIKEAuthenticationMethodSharedSecret;
        [self createKeychainValue:@"your_psk" forIdentifier:@"PSK"];
        p.sharedSecretReference = [self searchKeychainCopyMatching:@"PSK"];
    
        /*
         // certificate
         p.identityData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"client" ofType:@"p12"]];
         p.identityDataPassword = @"[Your certificate import password]";
         */
    
        //        p.localIdentifier = @"[VPN local identifier]";
        //        p.remoteIdentifier = @"[VPN remote identifier]";
        //
        p.useExtendedAuthentication = YES;
        p.disconnectOnSleep = NO;
    
        vpnManager.protocolConfiguration = p;
        vpnManager.localizedDescription = @"VPN Name";
    
    
        [[NEVPNManager sharedManager] setEnabled:YES];
    
    
    
        [vpnManager loadFromPreferencesWithCompletionHandler:^(NSError *error) {
            // do config stuff
            [vpnManager saveToPreferencesWithCompletionHandler:^(NSError *error) {
    
    
                if(error) {
                    NSLog(@"Save error: %@", error);
                }
                else {
                    NSLog(@"Saved!");
                }
    
    
            }];
        }];
    
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 2015-08-19
      • 2020-03-29
      • 2015-02-06
      相关资源
      最近更新 更多