Safari Content Blocker
Create Content Blocker Extension
Now that you have your basic application created we need to add a new application extension. We do this by going to File> New > Target. This will open up a Dialogue window for us and from that window, in the left hand side pane select Application Extension. Now, from the right main pane, select Content Blocker Extension:
Click Next. You will then be asked to name your content blocker. I have called this one SuperEvil.You will then get a message asking you to Activate “SuperEvil” Scheme. Click Activate:
Once that is done, go to your Project Navigation Pane. You should see a new folder called SuperEvil and a subfile of that folder called: blockerList.json. Double click that file. by default the code inside should be:[
[
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": "https?://(www.)?google.*" ////block specific url///////
}
},
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": ".*",
"resource-type": ["media"]
///block video, audio all types of media files for all websites///
}
}
]
Block phrases or urls with Safari Content Block
If any changes in "blockerlist.json" you have to reload. you have to call the below displayed function in "AppDelegate.m" in "didFinishLaunchingWithOptions" function.
or
AppDelegate.swift
import SafariServices
https://developer.apple.com/library/content/documentation/Extensions/Conceptual/ContentBlockingRules/CreatingRules/CreatingRules.html
Let me show you a very quick example. Let us assume that you are fed up of reddit. (For the record, I love reddit) You no longer want to display any pages from the reddit website. This includes subdomains. Then you would replace the above code with
[
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": ".*reddit.*"
}
}
]
Syntax
|
Description
|
|---|---|
.* |
The search matches all strings with a dot appearing zero or more times. Use this syntax to match every URL.
|
. |
The search matches any character.
|
\. |
The search explicitly matches the dot character.
|
[a-b] |
The search matches a range of alphabetic characters.
|
(abc) |
The search matches groups of the specified characters.
|
+ |
The search matches the preceding term one or more times.
|
* |
The search matches the preceding character zero or more times.
|
? |
The search matches the preceding character zero or one time.
|
url-filter-is-case-sensitive- The value associated with this key is a Boolean value. The default value is
false. if-domainorunless-domain- The value associated with this key is an array of strings. The strings are matched to the domain of the URL. The
if-domainfield limits the action to a specific list of domains. Theunless-domainfield acts on any site except domains in provided list. Triggers cannot have bothunless-andif-domainfields. Domain values must be lowercase ASCII. Use punycode to encode non-ASCII characters.Add the * character before the domain name to match the domain and any subdomains. For instance,*webkit.orgmatchesbugs.webkit.organdwebkit.org. resource-type- The value associated with this key is an array of strings representing the resource types that the rule should match. If not specified, the rule matches all resource types. The strings describes how the browser intends to use the resource, not necessarily the type of the resource itself. For example,
<img src="something.css">is identified as an image. Valid values forresource-typeare:documentimagestyle-sheetscriptfontraw(Any untyped load, such asXMLHttpRequest)svg-documentmediapopup
load-type- The value associated with this key is an array of strings. There are two possible values at this time and those values are mutually exclusive. If not specified, the rule matches all load types.
first-partyThe rule is triggered only if the resource has the same scheme, domain, and port as the main resource on the page.third-partyThe rule is triggered if the resource is not from the same domain as the main page resource.
If any changes in "blockerlist.json" you have to reload. you have to call the below displayed function in "AppDelegate.m" in "didFinishLaunchingWithOptions" function.
#import <SafariServices/SafariServices.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *id = [[NSString alloc]initWithString:@"com.gears42.Nix-Agent.contentBlock"];
[SFContentBlockerManager reloadContentBlockerWithIdentifier:id completionHandler:^(NSError * error){
if(error == nil){
NSLog(@"Reloaded");
}
else{
NSLog(@"Failed to reload:::%@",error);
}
}];
}
or
AppDelegate.swift
import SafariServices
func applicationDidBecomeActive(application: UIApplication) {
let blockerIdentifier = "com.appsfoundation.ContentBlocker.Blocke"SFContentBlockerManager.reloadContentBlockerWithIdentifier(blockerIdentifier) {error in if error == nil { print("Reloaded") } else { print(error) } }}https://developer.apple.com/library/content/documentation/Extensions/Conceptual/ContentBlockingRules/CreatingRules/CreatingRules.html
1 comment:
Casino Slot Machines | Play online at DrmCD
Enjoy an authentic Vegas-style online 아산 출장안마 casino game of slots, jackpots, and 남원 출장안마 table games at DrmCD. 영천 출장마사지 Explore 충청북도 출장샵 our wide selection of video slot games, 진주 출장안마
Post a Comment