Make basic content filter work on Mac Catalyst

Hello! New to swift development.

I've created a very basic iOS app that uses the network extension to block web domains.

Now, I am trying to make it work on a macOS using Mac Catalyst. However, when I build the project, I get this error:


2023-09-08 23:31:32.540010+0600 controlShift[69583:2468143] [Metadata] unable to get a dev_t for store 1795162192.



2023-09-08 23:31:33.986014+0600 controlShift[69583:2467453] [] -[NEFilterManager saveToPreferencesWithCompletionHandler:]_block_invoke_3: failed to save the new configuration: (null)

The app launches and the UI works correctly. However, it fails to save the preference as stated in the error, so it does not block anything.

Here is the relevant part of the code in the root file:

var body: some Scene {
        WindowGroup {
            ContentView()
                .environment(\.managedObjectContext, persistenceController.container.viewContext)
                .onAppear {
                    NEFilterManager.shared().loadFromPreferences { error in
                        if let loadError = error {
                            print("Failed to load the filter configuration: \(loadError)")
                            return
                        }
                    }
                    
                    DispatchQueue.main.asyncAfter(deadline: .now()+1.5) {
                        if NEFilterManager.shared().providerConfiguration == nil {
                            let newConfiguration = NEFilterProviderConfiguration()
                            newConfiguration.username = "UserName"
                            newConfiguration.organization = "myApp "
                            newConfiguration.filterBrowsers = true
                            newConfiguration.filterSockets = true
                            newConfiguration.serverAddress = "http://192.168.100.48:3000"
                            NEFilterManager.shared().providerConfiguration = newConfiguration
                        }

                        NEFilterManager.shared().isEnabled = true
                        NEFilterManager.shared().saveToPreferences { error in
                            if let saveError = error {
                                print("Failed to save the filter configuration: \(saveError)")
                            }
                        }
                    }
                }
        }

I'm at a loss for what is wrong. Lmk if you need additional details. Thanks!

btw, I am very new to swift and iOS/macOS development in general so if there's a better way to write or structure the logic inside the "onAppear" method (of which I'm sure there is), lmk as well. ^_^

Content filters on macOS are quite different from content filters on iOS, and so we don’t support Mac Catalyst for the extension. Rather, you’ll need to build a system extension for the Mac platform. For the details, see TN3134 Network Extension provider deployment.

You might be able to implement the container app as Mac Catalyst. I’ve not tried that combo, and for good reason: I don’t think that’s worth exploring. The bulk of the work here is in reworking your iOS content filter appex into a macOS content filter sysex. It’ll be relatively easy to port your SwiftUI container app from iOS to macOS.

Share and Enjoy

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

I see. I did as you instructed, but I'm still getting the same error.

2023-09-15 23:16:02.749005+0600 controlShift[81746:874607] [] -[NEFilterManager saveToPreferencesWithCompletionHandler:]_block_invoke_3: failed to save the new configuration: (null)

I have a suspicion that this might have to do with my computer specifically since I get the same error when I try to build and run this repo (https://github.com/anismansuri63/MacFilter) that I found online through this post (https://developer.apple.com/forums/thread/703655) while trying to find a solution to my problem. I could be wrong, but right now, I am unable to test this on a different computer.

If anyone has some insights into this, that'd be helpful. Thanks!

So, you were able to build your filter as a system extension? And activate that with the System Extension framework?

Share and Enjoy

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

Okay, you're right, I didn't activate the system extension correctly. Now that I have, I am getting this error:

Failed to register with the provider: Couldn’t communicate with a helper application.

For context, I have disabled my SIP and ran "systemextensionsctl developer on" in the terminal.

I used Apple's SimpleFirewall demo project (https://github.com/cntrump/SimpleFirewall) as a reference. The project runs fine on my system without any issues.

You don’t need to disable SIP, or turn on sysex developer mode, to work with NE sysexes. Moreover, disabling SIP is problematic and so I recommend that you not do it.

Rather, use the technique I describe in Debugging a Network Extension Provider to get your NE sysex running without disabling SIP.

Share and Enjoy

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

Make basic content filter work on Mac Catalyst
 
 
Q