Tech —

Explaining iOS 8’s extensions: Opening the platform while keeping it secure

Comparisons to Android's Intents only tell part of the story.

Apple's Craig Federighi introduces extensions at Apple's WWDC keynote.
Enlarge / Apple's Craig Federighi introduces extensions at Apple's WWDC keynote.
Apple

Of all the new features introduced in iOS 8 last week, app extensions are the ones that will have the biggest, most visible impact on the new operating system. The feature is most commonly described as a way for third-party applications to talk to each other, though that's an oversimplification—that's not the only thing app extensions can do, and technically third-party apps in iOS still can't talk directly to one another.

We've read the developer documentation and watched the WWDC sessions. Now it's time to break down how these features work, what they do, and how Apple is continuing to balance third-party access to the operating system with security.

What do app extensions do?

Choosing the type of extension you'd like to make in Xcode.
Enlarge / Choosing the type of extension you'd like to make in Xcode.
Apple

Allowing third-party apps to communicate with other apps is just one of the problems extensions are meant to solve—third-party keyboards, connecting apps to cloud services other than iCloud, and the new Notification Center widgets are all their own kind of extensions.

Not all parts of iOS can be changed (or "extended") by third parties. If you wanted to replace one of the default apps with your own or add some kind of toggle to the Control Center, you can't do that. Apple defines a handful of pre-set "extension points" to show developers where they can add stuff. The iOS 8 extension points are as follows:

  • Today extensions, also called widgets, are used to deliver glanceable information in the Today view in the Notification Center. Think of them as an answer to Windows Phone's Live Tiles or Android's home screen widgets.
  • Share extensions allow for the posting of photos, links, or other files from one app to an online service. This will enable things like posting pictures to Pinterest or uploading files from an app into Dropbox or OneDrive. Older versions of iOS support posting to Facebook and Twitter, and Share extensions open up the doors to others.
  • Action extensions "manipulate or view content within the context of another app." In English, that means editing a photo embedded in a text document or, as Apple showed onstage in the WWDC keynote, using something like Bing Translate to translate the text in a Safari window.
  • Photo Editing extensions can be used to take a picture you're viewing in Photos and call upon features from another app to edit it (Apple showed off a VSCO Cam extension in the keynote). Photos keeps both the edited image and the unedited original, though this isn’t true for video files.
  • Storage Provider extensions will let productivity apps open documents from a variety of cloud services. One could, for example, use Dropbox to store documents that you can then open and edit in Office for iPad or Pages.
  • Custom keyboard extensions replace the default Apple software keyboard with a new third-party one.

We'll focus primarily on iOS extensions today, but many of these (including Notification Center widgets and Share extensions, among others) work in OS X Yosemite just as they do in iOS. For apps in the Mac App Store tied to Apple's sandboxing restrictions they'll be useful, though of course many Mac apps continue to bypass the App Store and Apple's restrictions altogether.

This pre-set list of extension points differs from Android's Intents system. Android apps use "Intent Filters" to tell the operating system the kinds of things the apps can handle. The Twitter or Facebook apps can tell Android that they're capable of posting photos or links; Google Drive and Dropbox can be used to upload most kinds of files; Chrome and Firefox can open Web pages; new launchers can completely change the way your Home screen looks and works. Third-parties can even specify their own custom Intent Filters to the operating system. By contrast, iOS is still more limited (though not without reason, as we'll discuss later).

Keep this in mind, because it's going to come up a bunch: Extensions greatly increase the list of things third-parties can do, and for many common use cases they'll be functionally indistinguishable from Intents. The changes stop far short of Android's "anything goes" mentality, though, largely in the name of preserving iOS' security model.

How do you get extensions, and how do they work?

Extensions are delivered as binaries that live within a "containing app."
Enlarge / Extensions are delivered as binaries that live within a "containing app."
Apple

Like all third-party apps on a non-jailbroken iPhone, all iOS extensions are downloaded from the App Store. The biggest limitation here is that Apple won't allow developers to offer apps that are just extensions. Each extension has to live within a "containing app," and Apple mandates that the containing app must offer some functionality to the user. Unlike in Android, developers cannot offer apps that are just widgets or just keyboards (this applies only to iOS; OS X developers can offer apps that are simply wrappers for extensions).

This restriction sounds more onerous than it actually is. Look at Fleksy, a third-party keyboard app already offered through the App Store. Its containing app is little more than a keyboard tutorial, a field of text to practice in, and a settings panel. A basic Share button lets you send the text you type as an e-mail or Tweet. This app doesn't do a whole lot, but it's about as complicated as a containing app for a keyboard or widget would have to be.

Containing apps don't necessarily have to be complicated, but they do have to do something. The Fleksy keyboard's containing app is an extremely basic note-taking app primarily used for practicing.
Enlarge / Containing apps don't necessarily have to be complicated, but they do have to do something. The Fleksy keyboard's containing app is an extremely basic note-taking app primarily used for practicing.
Andrew Cunningham

Other things are recommended by Apple but not mandated. The company suggests that extensions be designed to complement Apple's built-in software. Third-party widgets should look and act like Apple's own widgets. Photo editing extensions that work with the Photos app shouldn't look radically different from that Photos app. There will definitely be developers who won't follow these guidelines, but most iOS app developers are already practiced at making apps that meld with Apple's UI.

While these guidelines are more restrictive than what Android developers will be used to, Apple imposes no limitations on the number or types of extensions your containing app offers. You can add an extension to your app by adding a new "target" to it in Xcode, and Apple provides default templates for all the different kinds of extensions.

Each type of extension is activated in different ways. Widgets are enabled and disabled from the Notification Center, and keyboards are changed in the Keyboards section of the Settings (where you'd go to select a different language or enable the emoji keyboard in iOS 7). Photo Editing and Storage Provider extensions only come up in specific situations—when using the Photos app and using any app that has a document picker, respectively. Share and Action extensions can be invoked from within any app, but developers should add Activation Rules to the extension to specify what kind of data it will work with. If your extension is only meant to share photos, Activation Rules can be configured to make sure that extension doesn't appear when the user is trying to share a URL or a document.

Activation rules tell the OS what kind of files your extensions can work with. You won't want to be offered a photo editing extension if you want to upload a document.
Enlarge / Activation rules tell the OS what kind of files your extensions can work with. You won't want to be offered a photo editing extension if you want to upload a document.
Apple

While they all need to be packaged up inside containing apps, extensions are generally run separately from the containing app itself. Each extension is its own little binary with an .appex file extension that can open, do its job, and close without ever running the containing app. For extensions that need to be able to perform some of the same tasks as their containing app—an Instagram extension that adds a filter to an image, for example—developers are encouraged to use an "embedded framework" to share the code responsible for those tasks. Create the framework, drop the code into it, and then embed that framework into both the containing app and the extension. The only caveat is that apps set up this way will require iOS 8.0 or later, and they won't run on earlier versions of the operating system.

One reason why extensions are launched separately from their containing apps is because of strict Apple-imposed memory limitations. Widgets are especially constrained, since the user can have many of them running at the same time. We'll have to see how a Notification Center packed with widgets will perform on a memory-constrained device like the iPhone 4S or the iPad 2.

Apple has designed extensions to have a "short lifecycle." They open, they do their job, and they close.
Enlarge / Apple has designed extensions to have a "short lifecycle." They open, they do their job, and they close.
Apple

Also, in part because of memory limitations, extensions don't run for very long and are aggressively cleared out of memory by the system. Extensions are designed to do their task and then get out of the way. For extensions that perform lengthy background tasks like uploading, Apple recommends that extensions pass that upload task to the system and then close down.

This covers the basics of how extensions are packaged, how they're accessed, and how they'll behave while they're running. Even with their restrictions, they stand to add a lot to the operating system—they're probably the biggest functional change we've gotten since iOS 4 or iOS 5. What's more impressive is the way these extensions work without sacrificing Apple's sandboxing model, which should help keep you and your data about as safe and as private as it can be these days.

Channel Ars Technica