safari-content-blocker

Determine if user has enabled application's Safari content blocker extension

眉间皱痕 提交于 2020-01-09 19:44:28
问题 I'm working on a Safari Content Blocking extension. I intend to show setup instructions if the extension is disabled and to show settings if it is conversely enabled. How can I determine if the extension is enabled by the user? I've seen this method to detect if a custom keyboard is activated but there's no key on NSUserDefaults that relates to Safari Content Blockers. 回答1: As of iOS 10, there is a new method in SFContentBlockerManager to support this: getStateOfContentBlocker(withIdentifier

Content Blocker extension with a String instead of a file

人走茶凉 提交于 2020-01-01 15:35:31
问题 I'm using the function NSItemProvider(contentsOfURL: NSBundle.mainBundle().URLForResource("blockerList", withExtension: "json") in a content blocker extension. The thing is that all my rules are stored in a few dictionaries and, when I'm using this function, it's always because the rules have changed. I'm currently creating a String from these dictionaries that looks like "[{\"trigger\": {\"url-filter\": \"webiste.com\"},\"action\": {"\type\": \"css-display-none\",\"selector\":\"

Multiple filters for Safari content blocking Swift

大城市里の小女人 提交于 2020-01-01 05:14:06
问题 I'm building a simple content-blockin app. It works, but i want to apply filters (which webs to block and which not) with UISwitches (saved to NSUserDefaults ). Because the content blocking extension uses json it's unclear to me how can i select multiple json files to function simultaneously. Any ideas how it can be achieved? Multiple extensions? Combining and splitting json files somehow? 回答1: I have been in same situation. Answer to this is bit tricky, so bear with me. You cannot write to

How do I know if my iOS Safari content blocker is enabled? [duplicate]

走远了吗. 提交于 2019-12-13 02:23:20
问题 This question already has answers here : Determine if user has enabled application's Safari content blocker extension (2 answers) Closed 3 years ago . Is there an iOS API that would tell me if my content blocker for Safari is enabled? Or do I have to resort to some kind of heuristics if I want to know that? 回答1: Have been wondering the same question and eventually came up with this method: break the structure of your .json file and see if you get an error in debuger. If you do - everything is

content blocker works in simulator but does not work in iPhone device

三世轮回 提交于 2019-12-08 16:25:52
问题 i am working on content blocker and block the adult site so, this code is perfect work on simulator when i test on iPhone 6 then its no one site is block Alamofire.request(url).responseJSON { response in if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) { print("Data: \(utf8Text)") self.containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.domainName.contentBlocker") let path = self.containerURL?.appendingPathComponent(

Using multiple JSON lists in iOS Content Blocker

筅森魡賤 提交于 2019-12-08 04:41:18
问题 I am trying to create my own content blocker on iOS. I was wanting to create separate json lists for different types of content (tracking, ads, adult sites, etc). I came across this https://github.com/calebhicks/ios-safari-content-blocking which stated you could create an array of "attachments" instead of relying on the singular "blockerList" json file. func beginRequest(with context: NSExtensionContext) { var jsonFiles:Array<NSItemProvider> = Array() let attachment = NSItemProvider

Content Blocker extension with a String instead of a file

烈酒焚心 提交于 2019-12-04 13:47:21
I'm using the function NSItemProvider(contentsOfURL: NSBundle.mainBundle().URLForResource("blockerList", withExtension: "json") in a content blocker extension. The thing is that all my rules are stored in a few dictionaries and, when I'm using this function, it's always because the rules have changed. I'm currently creating a String from these dictionaries that looks like "[{\"trigger\": {\"url-filter\": \"webiste.com\"},\"action\": {"\type\": \"css-display-none\",\"selector\":\".testContentBlocker\"}}]" and I have to transform it in a JSON file to finally be able to use it in the function

Multiple filters for Safari content blocking Swift

折月煮酒 提交于 2019-12-03 14:35:48
I'm building a simple content-blockin app. It works, but i want to apply filters (which webs to block and which not) with UISwitches (saved to NSUserDefaults ). Because the content blocking extension uses json it's unclear to me how can i select multiple json files to function simultaneously. Any ideas how it can be achieved? Multiple extensions? Combining and splitting json files somehow? I have been in same situation. Answer to this is bit tricky, so bear with me. You cannot write to file in bundle i.e blockerList.json is not writeable. Here is what you need to do, Enable App groups from

Determine if user has enabled application's Safari content blocker extension

青春壹個敷衍的年華 提交于 2019-11-29 01:26:52
I'm working on a Safari Content Blocking extension . I intend to show setup instructions if the extension is disabled and to show settings if it is conversely enabled. How can I determine if the extension is enabled by the user? I've seen this method to detect if a custom keyboard is activated but there's no key on NSUserDefaults that relates to Safari Content Blockers. As of iOS 10, there is a new method in SFContentBlockerManager to support this: getStateOfContentBlocker(withIdentifier:completionHandler:) And you call it like this (Swift 3): SFContentBlockerManager.getStateOfContentBlocker