Objective c iOS 8 VPN-网络扩展-连接\u块\u调用\u 2中出错

Objective c iOS 8 VPN-网络扩展-连接\u块\u调用\u 2中出错,objective-c,ios8,vpn,Objective C,Ios8,Vpn,我使用下面的代码来配置VPN - (void)setupConfiguration { NEVPNManager *manager = [NEVPNManager sharedManager]; int status = manager.connection.status; if (status == NEVPNStatusConnected) { [manager.connection stopVPNTunnel]; } else

我使用下面的代码来配置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设置导航到我们的应用程序时,我在日志-
“连接阻塞调用错误:连接中断”中收到此错误。之后,当我尝试连接到VPN服务器时,什么也没发生。

谁能帮我解决这个问题,为什么我会犯这个错误

注意:-我已经学习了以下教程:
1.
2

试试这个

// 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!");
            }


        }];
    }];

}];
试试这个

// 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!");
            }


        }];
    }];

}];