Jason
Jason

Reputation: 14615

Invoke Safari Content Blocker extension only when certain conditions are met?

Is it possible to get a Safari Content Blocker extension in iOS 9 to be invoked only when certain conditions are met - e.g. if it is within a certain time period (let's say you want to block trackers from 9-5 but not in the evening), or if you are on cellular? I know that in theory this could be done manually in the Settings app. But is there a way to make it automated, so you can just leave the content blocker on all the time?

Upvotes: 0

Views: 174

Answers (1)

Sansnagar
Sansnagar

Reputation: 124

Yes, i have done this. in my case there is a switch in the app so user can disable the content blocker without going to Setting app. I have done it by simply updating the json file at APP Group Container path whenever user disable the switch. In my case i am reading all blocker rules from blockerJson file from APP Main Bundle and put these rules in an array.then write this array of rules to BlockerJsonFile.json file at App group identifier container.

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

and when the user disable the switch then i update BlockerJsonFile.json file and make it empty and reload the content blocker using (SFContentBlockerManager.reloadContentBlockerWithIdentifier).

Upvotes: 1

Related Questions