I am attempting to share Core Data between a Network Extension and the containing application on MacOs. The Network Extension and containing application both have the same AppGroup entitlement and I use the following to get the URL for the storage:
let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "my-group-name")
For the containing application, the resulting URL is of the form:
/Users/***/Library/Group Containers/my-group-name
But for the Network Extension, the resulting URL is different:
/private/var/root/Library/Group Containers/my-group-name
Both the Network Extension and containing application can access their respective Core Data stores, but, of course, they are not shared since the URLs are different.
What am I missing? How is Core Data supposed to be shared between a Network Extension and the containing application?
And, if it matters, I am creating a DNSProxy type extension.
And, if it matters, I am creating a DNSProxy type extension.
That does matter. On macOS a DNS proxy provider is always packaged as a system extension and that means it runs as root. A shared container only works between two processes running as the same user. Given that your container app is running as some normal user and the provider is running as root, that can’t possibly work.
My general advice on this front is that you manage this state in your provider and then have the app get and modify the state in the provider via XPC.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"