YES its possible you can update the JSON blocklist
Step 1:
Create new JSON for content blocking rules
Step 2 :
Save the JSON file in Shared Container
fileprivate func saveRuleFile(ruleList:[Rule]) {
let encoder = JSONEncoder()
if let encoded = try? encoder.encode(ruleList) {
let sharedContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.xxx.xxxx.xxx")
print("sharedContainerURL = \(String(describing: sharedContainerURL))")
if let json = String(data: encoded, encoding: .utf8) {
print(json)
}
if let destinationURL = sharedContainerURL?.appendingPathComponent("Rules.json") {
do {
try encoded.write(to: destinationURL)
} catch {
print (error)
}
}
}
}
Step 3: Call this method to ask the Content blocker to reload the rules
SFContentBlockerManager.reloadContentBlocker(withIdentifier:"com.xxxx.xxx.xxxx", completionHandler: nil)
Step: 4
Read the JSON rules file from Shared container and pass the rules to content blocker extension
func beginRequest(with context: NSExtensionContext) {
let sharedContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.xxx.xxx.xxx")
let sourceURL = sharedContainerURL?.appendingPathComponent("Rules.json")
let ruleAttachment = NSItemProvider(contentsOf: sourceURL)
let item = NSExtensionItem()
item.attachments = ([ruleAttachment] as! [NSItemProvider])
context.completeRequest(returningItems: [item], completionHandler: nil)
}