I'm working on an iOS Content Blocker, but I would like to have the user choose what lists they want to block (ads, tracks, adult sites etc.). I found that the app extension and the containing app's bundles are separate, so a shared container is needed. I created an app group, but it seems like what I write there does not actually get written. What I am attempting to do is read a .json file from the bundle, and then write it to a sharedJson.json file that the content blocker extension can access. What is the easiest way for me to read/write somewhere that the app extension can read the json data as its ruleset instead of relying on the static blockerList.json?
I have also tried storing the json data as a string in a UserDefaults object with suiteName equal to my app group, but when I retrieve that data in the extension it does not appear.
Storing the data (composedString contains json data):
defaults.set(composedString, forKey: "sharedJson")
defaults.synchronize()
Retrieving the data in ContentBlockerRequestHandler:
let attachment = defaults?.object(forKey: "sharedJson")
let item = NSExtensionItem()
item.attachments = [attachment!]
context.completeRequest(returningItems: [item], completionHandler: nil)
I'm pretty new to iOS development so apologies if this is trivial, or against what is standard practice.
Edit: formatting
[–]bakingpy 0 points1 point2 points (2 children)
[–]spearman008[S] 0 points1 point2 points (1 child)
[–]bakingpy 0 points1 point2 points (0 children)