Passing nil to NEFilterDataProvider.apply(_:completionHandler:) causes error and doesn't apply default settings as documented

I'm trying to adapt the Filter Network Traffic sample code found at https://developer.apple.com/documentation/networkextension/filtering_network_traffic

In FilterDataProvider.swift I've replaced the argument passed to NEFilterDataProvider.apply(_:completionHandler:) with nil, which according to the documentation should apply the default settings. Instead I'm getting the following error:

Error Domain=NEFilterErrorDomain Code=1 "The settings parameter doesn’t correspond to a NEFilterSettings object" (translated from my local language)

(When logging the error with os_log, the Console app just shows it as <private>. A NSLog call instead displays it correctly.)

After that the internet doesn't seem to work at all anymore and I have to trash the app to make the internet work again. (If the bin is not completely empty before trashing the app from the Applications folder, I'm prompted that there is another operation in progress like moving a file.)

If a nil parameter doesn't work, what is the correct way of not filtering anything, but just observing all the network traffic?

AFAICT the docs are just wrong here. I took a look at the code and the first thing it does is fail with that error if that parameter is nil or of the wrong class. Please file a bug against the docs, and post your bug number, just for the record.

If a nil parameter doesn't work, what is the correct way of not filtering anything

The page you reference describes how a default filter settings object is constructed. However, I’m not sure that achieves this goal:

but just observing all the network traffic?

The default action, NEFilterActionFilterData, still filters, it’s just that your data provider gets to see the traffic and programmatically decide how to filter.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Passing nil to NEFilterDataProvider.apply(_:completionHandler:) causes error and doesn't apply default settings as documented
 
 
Q