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. ^_^