停止显示NEVPNProtocolIPSec错误警报并通过代码捕获它

时间:2019-04-17 18:37:24

标签: ios swift

我使用NEVPNProtocolIPSec()快速连接到我的vpn,但是当连接发生错误时,它会显示该错误的alertView,例如http://i.imgur.com/q3irLTF.png 但是我想通过我的代码处理这些错误,并停止显示这些警报视图并显示我的自定义警报视图

let p = NEVPNProtocolIPSec()
        p.username = config.account
        p.passwordReference = config.getPasswordRef()
        p.serverAddress = config.server
        if config.pskEnabled {
            p.authenticationMethod = NEVPNIKEAuthenticationMethod.sharedSecret
        } else {
            p.authenticationMethod = NEVPNIKEAuthenticationMethod.none
        }
        p.sharedSecretReference = config.getPSKRef()
        p.useExtendedAuthentication = true
        loadProfile { _ in
            self.manager.protocolConfiguration = p
            if config.onDemand {
                self.manager.onDemandRules = [NEOnDemandRuleConnect()]
                self.manager.isOnDemandEnabled = true
            }
            self.manager.isEnabled = true
            self.saveProfile { success in
                if !success {
                    onError("Unable to save vpn profile")
                    return
                }
                self.loadProfile() { success in
                    if !success {
                        onError("Unable to load profile")
                        return
                    }
                    let result = self.startVPNTunnel()
                    if !result {
                        onError("Can't connect")
                    }
                }
            }
        }

0 个答案:

没有答案