Chapter 5. 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 a developer 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 sit inside 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.

5.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 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; e.g., whether you want to block images, style sheets, etc. The user can then, after opening your app at least once, go into the settings ...

Get iOS 9 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.