Hello, I'm experiencing an issue with enabling a Content Filter Network Extension from a command line tool. When I call the LoadFromPreferences method on NEFilterManager.shared() the completion handler is not called.
I've tried this with a simple semaphore and tried running it on a RunLoop, but none of this works.
Any help would be appreciated.
I've tried adding a small demo project illustrating the issue, but the add file option does not seem to work.
I'll paste the code here:
Semaphore Demo
class SemaphoreDemo {
let filterManager = NEFilterManager.shared()
var semaphore = DispatchSemaphore(value: 0)
func demo() {
print("Semaphore demo")
self.filterManager.loadFromPreferences { (error) in
print("Load from preferences callback")
if let error = error {
print("ERROR \(error.localizedDescription)")
return
}
let config = NEFilterProviderConfiguration()
config.filterDataProviderBundleIdentifier = "BUNDLE_IDENTIFIER"
config.filterSockets = true
self.filterManager.isEnabled = true
self.filterManager.localizedDescription = "LOCALIZED_DESCRIPTION"
self.filterManager.providerConfiguration = config
self.filterManager.saveToPreferences { (error) in
if let error = error {
print("ERROR \(error.localizedDescription)")
} else {
print("SUCCESS")
}
self.semaphore.signal()
}
}
self.semaphore.wait()
}
}
class RunloopDemo {
let filterManager = NEFilterManager.shared()
func demo() {
print("Runloop demo")
let currentRunLoop = CFRunLoopGetCurrent()
// let currentRunLoop = CFRunLoopGetMain()
self.filterManager.loadFromPreferences { [weak currentRunLoop] (error) in
print("Load from preferences callback")
if let error = error {
print("ERROR \(error.localizedDescription)")
return
}
let config = NEFilterProviderConfiguration()
config.filterDataProviderBundleIdentifier = "Bundle IDENTIFIER"
config.filterSockets = true
self.filterManager.isEnabled = true
self.filterManager.localizedDescription = "LOCALIZED DESCRIPTION"
self.filterManager.providerConfiguration = config
self.filterManager.saveToPreferences { (error) in
if let error = error {
print("ERROR \(error.localizedDescription)")
} else {
print("SUCCESS")
}
CFRunLoopStop(currentRunLoop)
}
}
CFRunLoopRun()
}
}
The callback is never called.
Thanks.