(Apparently only answers get formatting, so this isn't an answer but here it goes anyway.)
My code is shamefully bad, of course. I can hopefully be forgiven due to the lack of sample code...
I have "class AppProxyProvider: NEAppProxyProvider" in the extension; however, it does not seem to load. Interestingly, I can see it in Network preferences -- but it says "Please use 'AppProxyTest' to control this content filter configuration." But then I'm back to not sure what I'm supposed to do...
This is the code I'm using to try to load it; there is a lot of extraneous code in there, I'm aware, as well as a lot of prints, because those continue to be my favourite method for tracing progress. I have os_log() calls in the extension, but as I said, it doesn't seem to get loaded.
private func loadExtension() {
guard let extensionIdentifier = extensionBundle.bundleIdentifier else {
print("Can't get the extension identifier")
return
}
NEAppProxyProviderManager.loadAllFromPreferences() { providers, error in
if let err = error {
print("Got provider manager error \(err.localizedDescription)")
} else {
print("providers = \(providers)")
}
}
let activationRequest = OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: extensionIdentifier, queue: .main)
activationRequest.delegate = self
OSSystemExtensionManager.shared.submitRequest(activationRequest)
os_log("Bundle ID = %{public}@", activationRequest.identifier)
let filterManager = NEFilterManager.shared()
filterManager.loadFromPreferences { error in
if error != nil {
print("The first loadFromPreferences got error \(error)")
} else {
print("Was able to load filterManager preferences the first time")
}
}
if filterManager.providerConfiguration == nil {
let providerConfiguration = NEFilterProviderConfiguration()
providerConfiguration.filterSockets = false
providerConfiguration.filterPackets = true
filterManager.providerConfiguration = providerConfiguration
if let appName = Bundle.main.infoDictionary?["CFBundleName"] as? String {
filterManager.localizedDescription = appName
}
print("providerConfiguration = \(providerConfiguration)")
} else {
print("filterManager.providerconfiguration = \(filterManager.providerConfiguration)")
}
filterManager.isEnabled = true
filterManager.localizedDescription = "Test App Proxy Provider"
print("filterManager = \(filterManager)")
filterManager.saveToPreferences { saveError in
if saveError == nil {
return
}
if let error = saveError as NSError? {
print("Failed to save the filter configuration: \(error)")
}
}
filterManager.loadFromPreferences() { error in
if let err = error {
print("The second loadFromPreferences got error \(err.localizedDescription)")
}
}
}