@@ -119,19 +119,49 @@ - (void)addControlPanelToNavigate{
119
119
[_webView addSubview: forwardButton];
120
120
}
121
121
122
-
123
122
- (void )configureWebView {
124
123
125
124
if (!_webView) {
126
125
WKPreferences *webViewPreferences = [[WKPreferences alloc ] init ];
127
126
[webViewPreferences setJavaScriptEnabled: false ];
128
127
WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc ] init ];
128
+
129
+ if (@available (iOS 11.0 , *)) {
130
+
131
+ NSMutableDictionary *urlFilter = [[NSMutableDictionary alloc ] init ];
132
+ [urlFilter setObject: @" .*" forKey: @" url-filter" ];
133
+
134
+ NSMutableDictionary *type = [[NSMutableDictionary alloc ] init ];
135
+ [type setObject: @" block" forKey: @" type" ];
136
+
137
+ NSMutableDictionary *blockRules = [[NSMutableDictionary alloc ] init ];
138
+ [blockRules setObject: urlFilter forKey: @" trigger" ];
139
+ [blockRules setObject: type forKey: @" action" ];
140
+
141
+ NSMutableArray *blockRulesArray = [[NSMutableArray alloc ] init ];
142
+ [blockRulesArray addObject: blockRules];
143
+
144
+ NSData * jsonData = [NSJSONSerialization dataWithJSONObject: blockRulesArray options: NSJSONWritingPrettyPrinted error: nil ];
145
+
146
+ NSString * newStr = [[NSString alloc ] initWithData: jsonData encoding: NSUTF8StringEncoding];
147
+
148
+ [[WKContentRuleListStore defaultStore ] compileContentRuleListForIdentifier: @" ContentBlockingRules" encodedContentRuleList: newStr completionHandler: ^(WKContentRuleList *blockList, NSError *error) {
149
+
150
+ if (error != nil ) {
151
+ return ;
152
+ }
153
+ [webViewConfiguration.userContentController addContentRuleList: blockList];
154
+
155
+ }];
156
+ }
157
+
129
158
webViewConfiguration.preferences = webViewPreferences;
130
159
_webView = [[WKWebView alloc ] initWithFrame: self .frame configuration: webViewConfiguration];
131
160
_webView.navigationDelegate = self;
132
161
_webView.scrollView .delegate = self;
133
162
[self addSubview: _webView];
134
163
}
164
+
135
165
_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
136
166
}
137
167
0 commit comments