Is there a Delegate for the Wireguard status in PacketTunnelProvider (iOS)

Houman houmie at gmail.com
Sat Feb 19 17:34:50 UTC 2022


Hello,

I wonder if there is a Delegate we could use in PacketTunnelProvider
to observe the state of Wireguard VPN.

For example OpenVPN has something like this:

extension PacketTunnelProvider: OpenVPNAdapterDelegate {
    func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleEvent
event: OpenVPNAdapterEvent, message: String?) {
        switch event {
        case .connected:
        case .disconnected:
        case .reconnecting:
        default:
            break
        }
    }
}

Do we have this in Wireguard?

I know it's possible to subscribe to this NEVPNStatusDidChange in the
main app instead:

override func viewDidLoad() {
    NotificationCenter.default.addObserver(self, selector:
#selector(vpnStatusDidChange(_:)), name:
NSNotification.Name.NEVPNStatusDidChange, object: nil)
}

But this doesn't work well for Third party VPNs that integrate over
the NetworkExtension framework. Even though I have observed this once,
I see multiple connected states being triggered, after connecting a
single time to the VPN.

@objc private func vpnStatusDidChange(_ notification: Notification) {
        let nevpnconn = notification.object as! NEVPNConnection
        let status = nevpnconn.status
        switch status {
        case NEVPNStatus.invalid:
        case NEVPNStatus.disconnected:
        case NEVPNStatus.connecting:
        case NEVPNStatus.connected:
...
}

Any suggestions please?
Thanks,


More information about the WireGuard mailing list