iOS9 Safari content blocker extension not invoked

3.1k views Asked by At

I'm playing with XCode7 beta, trying to test the shiny new "Content Blocker Extension". The example class is adopting the same NSExtensionRequestHandling protocol as the (already known) Sharing extension. The essential difference from Sharing extension is that the class is a plain NSObject, not a *ViewController subclass because, you know, a Blocker Extension isn't supposed to be showing any UI feedback. That's my understanding at least. Anyway the crucial method beginRequestWithExtensionContext which is supposed to feed the blocker declaration JSON to the extension point, does not get invoked. The extension does have TRUEPREDICATE as its NSExtensionActivationRule and Safari does acknowledge the existence of my host app in the new Safari config "Content Blockers". But still no cigar.

Does anybody know if it's even supposed to be already working this early in the beta or was it just a press release?

And, oh, while we're at it, is there any documentation of that declarative JSON format or it's just my Google-Fu failing me? :)

4

There are 4 answers

5
Chris Jones On BEST ANSWER

How do you know the extension isn't getting invoked?

I built a very quick test app and did a simple NSLog() from the beginRequestWithExtensionContext method and it was getting called when the extension was switched on.

Also, fwiw, there's +[SFContentBlockerManager reloadContentBlockerWithIdentifier:completionHandler:] which lets you trigger an update from the main app, at will.

1
Itay Brenner On

There isn't any documentation yet, but I found that some characters in the url prevent the load of the JSON They are (the one I found, might be more): +(as prefix) , $, |, ^

1
pkamb On

Is there any documentation of that declarative JSON format

The webkit.org blog post below seems to be the current best "official" documentation of the Content Blocker JSON format.

https://www.webkit.org/blog/3476/content-blockers-first-look/

0
Johannes Schröter On

Use the device console to view a live log of the device. There you will see your NSLog() calls.

  1. Choose Window -> Devices from the Xcode menu.
  2. Choose the device in the left column.
  3. Click the up-triangle at the bottom left of the right hand panel to show the device console.