Chapter 12. Extensions
Apple increased the number of extensions that we developers can write in the new iOS. One of the hot extensions that everybody seems to be talking about is the Safari Content Blocker, which allows developers to specify which URLs or resources should get blocked in Safari tabs.
Extensions are separate binaries that sit inside your app’s bundle. They usually have their own naming convention and are contained in reserved folders inside your app bundle. It’s best not to mention what they are called on disk, because Apple can change that at any time without us knowing. Because extensions sit in their own folders and have their own bundles, they do not share the same physical space as their container app. But, through some work, they can access the container app’s resources, such as images and text.
12.1 Creating Safari Content Blockers
Problem
You want to create a content blocker that the user can add to her Safari browser for blocking specific web content.
Solution
Use the Safari Content Blocker extension.
Discussion
This is something I am very excited about. You can ignore the long list of content blockers popping up on the App Store every day from now on.
This is how the Apple blocker works. When you create an app, you can add a Safari Content Blocker extension to it. In that extension, you define the rules for your content blocking (whether you want to block images, stylesheets, etc.). The user can then, after opening your app at least once, go into ...
Get iOS 11 Swift Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.