jasono
jasono

Reputation: 213

Does anyone know how you actually update the blockerList.json file for the safari content blocker?

Apple has provided us with an API to update the json used for safari content blockers (SFContentBlockerManager.reloadContentBlockerWithIdentifier) so it's clear that Apple intends for us to make the blocked items customizable.

I've been playing around with it for quite some time now and I'm unable to figure out how you would actually do this.

I've tried different json files to load into the extension (one for ads, one for sites, etc) but sending in more than one file always seems to just break the extension for me.

I've also tried editing the blockerList.json file from within the app but that also seems to break the extension. I've also been told that we're not allowed to edit a resource that is bundled with our app.

The documentation for modifying what content is blocked seems to be nonexistent. Does anyone have an example or at least a link to some documentation that I could use?

Thanks

Upvotes: 4

Views: 1171

Answers (1)

Sansnagar
Sansnagar

Reputation: 124

i have done this customization last week. instead of passing multiple jsons to extension, you should read all rules(ads,sites etc.) from json files of application's main bundle in a array and then write this array of rules in a new json file and save this json to APP group container path as

[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:YOUR_APP_GROUP_IDENTIFIER] URLByAppendingPathComponent:@"SharedJsonFile.json"]

and in extension's beginRequestWithExtensionContext method, load json from path as

NSURL *jsonPath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:YOUR_APP_GROUP_IDENTIFIER] URLByAppendingPathComponent:@"SharedJsonFile.json"]; 

So if you want to apply only ads rules and escaping sites rules then you have to update SharedJsonFile.json file to contain array of ads rules only and then reload your content blocker using (SFContentBlockerManager.reloadContentBlockerWithIdentifier).

Upvotes: 3

Related Questions