DevShark
DevShark

Reputation: 9122

NEFilterProvider record network activity

NEFilterProvider, or more specifically its 2 subclasses NEFilterDataProvider and NEFilterPacketProvider, has the functionality to allow or deny network activity. However, I couldn't find any way to log in the activity, for debugging purposes.

I know the documentation says this:

it runs in a very restrictive sandbox. The sandbox prevents the Filter Data Provider extension from moving network content outside of its address space by blocking all network access, IPC, and disk write operations.

but is there any trick to log this anyway in debug mode? Maybe using os_log or something like that?

Upvotes: 1

Views: 454

Answers (1)

Jared Henderson
Jared Henderson

Reputation: 1319

yes, you can use os_log and read the output in the Console app. if you want to workaround the privacy restrictions (while developing/testing), use the %{public} prefix, like so...

import os.log

// ...somewhere in the provider class
os_log("something i want to log %{public}@", someVar)

you're right, the documentation is really, really lacking for this area, other than the SimpleFirewall sample code, and wwdc video. i have an app in production using NEFilterDataProvider but it about cost me my sanity to figure out how to put it all together. at some point i'm going to try to write some blog posts or make a demo repo to try to help create a central community resource to share knowledge and fill in the gaps in the documentation with hard-won knowledge.

Upvotes: 1

Related Questions