I followed your advice and tried to first test access to the shared container and everything worked as expected: Filter Data and Filter Control Providers were able to read from app group container and main target was able to write data. After that I tried to add Core Data like this:
private lazy var persistentContainer: NSPersistentContainer = {
guard let sharedContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "MyGroupIdentifier") else {
fatalError("Shared container is not accessible.")
}
let storeURL = URL.storeURL(group: "MyGroupIdentifier", database: "MyCoreDataModel")
let description = NSPersistentStoreDescription(url: storeURL)
let container = NSPersistentContainer(name: "MyCoreDataModel")
container.persistentStoreDescriptions = [description]
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
public extension URL {
static func storeURL(group: String, database: String) -> URL {
guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: group) else {
fatalError("Shared file container could not be created.")
}
return fileContainer.appendingPathComponent("\(database).sqlite")
}
}
My VM in the main app target stores Model shared instance and everything compiled as expected. However, if I try to call let's say fetch for database, Content Filter becomes Invalid. I had similar problem, when I tried to add async operation to my Filter Data Provider handleNewFlow func in order to store intercepted flows, that's why I moved logic to VM and UserDefaults at that time
Topic:
App & System Services
SubTopic:
Networking
Tags: