The code to restart the Network Extension is as follows:
public func stopTunnel(_ manager: NETransparentProxyManager? = nil) async throws -> Bool {
LogInfo("start stopTunnel")
let proxyManager: NETransparentProxyManager
if let manager = manager {
proxyManager = manager
} else {
proxyManager = try await getManager()
}
let session = proxyManager.connection as? NETunnelProviderSession
session?.stopTunnel()
let isRunning = try await queryStatus(manager)
LogInfo("finished stopTunnel")
return !isRunning
}
public func getManager() async throws -> NETransparentProxyManager {
let managers = try await NETransparentProxyManager.loadAllFromPreferences()
if managers.count <= 0 {
//New installation scenario
LogInfo("config no NETransparentProxyManager, new installation scenario")
}
let appManager = managers.first ?? NETransparentProxyManager()
return appManager
}
public func startTunnel(_ manager: NETransparentProxyManager? = nil, options: [String: Any]? = nil) async throws -> Bool {
LogInfo("start startTunnel")
let proxyManager: NETransparentProxyManager
if let manager = manager {
proxyManager = manager
} else {
proxyManager = try await getManager()
}
try await proxyManager.loadFromPreferences()
let session = proxyManager.connection as? NETunnelProviderSession
try session?.startTunnel(options: options)
LogInfo("finished startTunnel")
return true
}
Restart the Network Extension by calling the stopTunnel function followed by the startTunnel function.
Regarding the second issue you mentioned, I understand it refers to the scenario:“You have an existing flow object that’s successfully run through the above sequence. Then, without an obvious cause, your -writeXyz calls start failing with the above-mentioned error (NEAppProxyErrorDomain / 1)