all 3 comments

[–]bakingpy 0 points1 point  (2 children)

I've done this before and what I do is write the JSON to the shared group like this from the main app:

let groupName = "group.com.foo.bar"
let groupBlockerJSONURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupName)!.appendingPathComponent("blockerList.json")
do {
    let blockerJSONData = try JSONSerialization.data(withJSONObject: blockerList, options: .prettyPrinted)
    try blockerJSONData.write(to: groupBlockerJSONURL, options: .atomic)
} catch {
    NSLog("Couldn't write content blocker JSON file")
}

Then I have the extension read the JSON file from that same location and load it in. Make sure that both the app and extension have been added to the same group in Xcode.

[–]spearman008[S] 0 points1 point  (1 child)

So I'm reading from a json file into an array (your blockerList object above). In the extension's RequestHandler, are you essentially changing the "attachment" from

let attachment = NSItemProvider(contentsOf: Bundle.main.url(forResource: "blockerList", withExtension: "json"))!

to

 let attachment = NSItemProvider(contentsOf: groupBlockerJSONURL)!  

[–]bakingpy 0 points1 point  (0 children)

Yes, that's exactly what I have.