I have heard that iOS has support for content blockers, and that all blocking is done by a file called blockerList.json
that resides in the App Bundle. While I know that SFContentBlockerManager.reloadContentBlockerWithIdentifier()
will reload the data in blockerList.json
. However, I don't see any use in this; the blockerList.json
is part of the main bundle and can't be modified. Thus, is there any way that the blockerList.json
can be modified (or the extension can point to another file, be deleted and recreated, not use JSON, etc.)?
Asked
Active
Viewed 2,017 times
5

saagarjha
- 2,221
- 1
- 20
- 37
2 Answers
5
You don't have to use blockerList.json
from the bundle as your JSON source. There are a couple different things you can do to dynamically change the content blocker.
- You could have the extension download a new JSON file from a server and update the blocker when triggered by the app
- Put the app and content blocker extension in the same app group so data can be passed between the two and then do one of the following:
- Have the app create/modify a JSON file in the shared group directory that will be read by the extension
- Have the app write data to the shared group user defaults and then have the extension create a JSON file for it to load

user3060016
- 74
- 2
-
1Could you explain how to trigger blocker extension from app? – liudanking Sep 30 '16 at 06:46
2
Yes i have done this by reading all blocking rules from mainbundle json file and created a json file(i.e. SharedJsonFile.json) in App Group identifier container. Then i wrote all rules to SharedJsonFile.json.
[[NSFileManager defaultManager]
containerURLForSecurityApplicationGroupIdentifier:YOUR_APP_GROUP_IDENTIFIER]
URLByAppendingPathComponent:@"SharedJsonFile.json"]
So whenever i want to make modifications and i update SharedJsonFile.json and then reload contentblocker.
To read the json i have used this URL path in extension's beginRequestWithExtensionContext
method -
NSURL *jsonPath = [[NSFileManager defaultManager]
containerURLForSecurityApplicationGroupIdentifier:YOUR_APP_GROUP_IDENTIFIER]
URLByAppendingPathComponent:@"SharedJsonFile.json"];

Sangram Shivankar
- 3,535
- 3
- 26
- 38

Sansnagar
- 124
- 6