7

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? :)

Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
  • Got the same problem. `beginRequestWithExtensionContext` not called. BTW, `blockerList.json` seems that JSON file can't be modified by the extension on the fly. So, there is no way to make settings UI for extension/app? To modify filters you need to republish extension? – Wayne Jun 22 '15 at 14:07
  • 2
    There is this [`reloadContentBlocker...`](https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS90APIDiffs/frameworks/SafariServices.html) which @chris-jones pointed out as being meant to force reloading from your host app. – Pavel Zdenek Jun 23 '15 at 20:54
  • Same problem here, did you ever find a solution? – mmc Jul 22 '15 at 23:31
  • I have problems testing because my device isnt 64bit, and they only work for 64bit devices! – mcfedr Aug 23 '16 at 09:44
  • @mcfedr yes only 64bit. Fun thing is that it was a last minute change, the restriction note was added to the [relevant Apple dev doc](https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ContentBlocker.html) like a month before iOS9 release. – Pavel Zdenek Nov 07 '16 at 20:21
  • The most difficult bit, that i only discovered at the point of trying to upload, is that you cannot have a app that is 32 and 64 bit, with the extension only working for 64 bit devices. I have had to roll out a separate app with the extension and communicate between two apps – mcfedr Nov 07 '16 at 20:23
  • That is, you cannot upload such and app to the store, you can create such an app in xcode, and run it on devices with no problems, but you cannot submit it. – mcfedr Nov 07 '16 at 20:24

4 Answers4

5

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.

Chris Jones
  • 456
  • 2
  • 8
  • 2
    No log, no breakpoint hit for me. Seeing your post, i even dumbly tried to make a new app in ObjC instead of Swift. The extension is playing possum. Could you publish your host app repo somewhere? – Pavel Zdenek Jun 11 '15 at 08:36
  • Apologies for the slow reply: https://github.com/cmsj/iOS9ContentExtensionTest - the "BLOCK ALL THE THINGS" folder is the extension, and "The Blocker" is the iOS app. It has almost zero features :) – Chris Jones Jul 23 '15 at 14:39
  • 2
    I forked your repo, built it and does *not* WFM :( `reloadContentBlockerWithIdentifier` didn't even call the completion handler in XCode7b3, and calls it with `ContentBlockerErrorDomain Code=3` in latest XCode7b5. The blocker extension isn't even instantiated, the less executed `beginRequestWithExtensionContext`. Could you check it please? It's true that i didn't have the `reloadContentBlockerWithIdentifier` call but if you were testing with older XCode7 beta, it might be broken for you too now. If not... i'm going to freak out. – Pavel Zdenek Aug 07 '15 at 17:17
  • 2
    So i'm accepting your answer. It's not giving the silver bullet which i wanted, but basically it's what you said: it is supposed to work. Now with iOS9 out, it clearly works :) On my side, it was enough to ditch the testing project which i created in XCode7b1, and make it again in XCode7 GM. Exactly the same bare bones code. I will never know what was the problem, but i don't care anymore. – Pavel Zdenek Oct 06 '15 at 11:25
  • Also really useful it gives you an `NSError` object explaining any problems, found that great for debugging issues with the JSON. – mcfedr Jul 26 '16 at 18:55
2

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) , $, |, ^

Itay Brenner
  • 800
  • 6
  • 19
2

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/

pkamb
  • 33,281
  • 23
  • 160
  • 191
  • 1
    Half a year later, it still seems to be the only documentation available. I know about it now, but it was posted 2 days after my question :) – Pavel Zdenek Oct 06 '15 at 11:32
1

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.