WKContentRuleList是应用于Web内容的编译规则列表,适用于 iOS11.0+ 的设备。我们可以通过给webView.configuration.userContentController添加WKContentRuleList,使WebView的加载遵守相关规则。
记录下
- 优酷moblie视频播放拦截json
[{"trigger" : {"url-filter" : ".*cp31.ott.cibntv.net\/.*"},"action" : {"type" : "block"}},
{"trigger" : {"url-filter" : ".*pl-ali.youku.com.*"},"action" : {"type" : "block"}}]
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[self configMakeHttps] options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
WKUserContentController *_userContentController = [[WKUserContentController alloc] init];
WKWebViewConfiguration *_configuration = [[WKWebViewConfiguration alloc] init];
if (@available(iOS 11.0, *)) {
[[WKContentRuleListStore defaultStore] compileContentRuleListForIdentifier: @"ContentBlockingRules" encodedContentRuleList: jsonStr completionHandler:^(WKContentRuleList *contentRuleList, NSError *error) {
[_configuration.userContentController addContentRuleList:contentRuleList];
}];
} else {
// Fallback on earlier versions
}
网友评论