That's great to hear! I'll try again.
Here's what I tried but does not work:
- 1 system extension : MyDataAndPacketFilter.systemExtension
+ It's Info.plist contains this :
<dict>
<key>NEProviderClasses</key>
<dict>
<key>com.apple.networkextension.filter-data</key>
<string>$(PRODUCT_MODULE_NAME).FilterDataProvider</string>
<key>com.apple.networkextension.filter-packet</key>
<string>$(PRODUCT_MODULE_NAME).FilterPacketProvider</string>
</dict>
</dict>
</plist>
- 1 File FilterDataProvider.swift :
class FilterDataProvider: NEFilterDataProvider {
override init() {
super.init()
os_log(" FilterDataProvider init")
}
override func startFilter(completionHandler: @escaping (Error?) -> Void) {
os_log("FilterDataProvider startFilter")
}
override func stopFilter(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
os_log("FilterDataProvider stopFilter")
completionHandler()
}
}
- 1 File FilterPacketProvider.swift :
class FilterPacketProvider: NEFilterPacketProvider {
override init() {
super.init()
os_log("FilterPacketProvider init")
}
override func startFilter(completionHandler: @escaping (Error?) -> Void) {
os_log("FilterPacketProvider startFilter")
}
completionHandler(nil)
}
override func stopFilter(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
os_log("FilterPacketProvider stopFilter")
completionHandler()
}
}
- In the main app (gui app), I do this:
+ load the 2 system extensions. This works fine
+ enable the filter via this :
func startFilter() {
let filterManager = NEFilterManager.shared()
loadFilterConfiguration { success in
guard success else {
os_log("Eror in startFilter")
return
}
let providerConfiguration = NEFilterProviderConfiguration()
providerConfiguration.filterPackets = true //
providerConfiguration.filterSockets = true // I set both to true
filterManager.providerConfiguration = providerConfiguration
filterManager.localizedDescription = appName
filterManager.isEnabled = true
filterManager.saveToPreferences { saveError in
DispatchQueue.main.async {
if let error = saveError {
os_log("Failed to save the filter configuration: %@", error.localizedDescription)
return
}
}
}
}
This does not work, as only 1 startFilter is called (the one of FilterDataProvider).
Can you tell what I am doing wrong?
Thanks!