Action extensions in iOS 8: Explained

Share Sheets in iOS have another name behind the scenes — activity view controllers. That's fitting because, in addition to providing sharing options, they also provide for other "activities", like action options. Traditionally, that's been system options such as copy, save, print, etc. However, just like custom sharing options have now been made available in iOS 8, so too have custom action options. They're part of the new Extensibility feature set, one of the most important additions to iOS since the advent of the App Store. Extensibility enables Widgets, custom keyboards, and so much more, including custom action extensions. So, how do action extensions work?

Action packed

Action options first came to iOS as part of the same drab lists that contained share options. Not only did that fail to provide a lot of visual distinction, it didn't scale.

When share options moved to the grid-like Share Sheets in iOS 6, actions joined them. There, share options got the full color icons of the apps with which they were associated, and action options got custom, grayscale icons that indicated their function — save to Camera Roll, print to AirPrint, copy to clipboard, etc. Share and action options still ran together, however, and the grid scaled only slightly better than the list.

With iOS 7, Share Sheets got a new look and feel to match Apple's new design language, and actions switched from being grayscale to black and white. Moreover, actions got their own distinct row along with horizontal scrolling to fit in as many as needed. However, there were still only a very few action options, and only the ones that matched services Apple provided.

iOS 8 changes that.

How action extensions work

Extensibility in iOS 8 means that we're not longer bound to action options supported by Apple and Apple alone. We no longer have to wait for things like AirPlay and AirPrint to be rolled out, or wonder if Apple will ever add system-wide support for someone else's product or service. Now any app can add an action extension that increases the utility and diversity of other apps and iOS itself.

So, instead of Apple and Microsoft making a deal to get Bing translate built into Safari, Microsoft can simple make an action extension to the Bing app and, thanks to Extensibility, it'll be available just like the built in options.

Getting to an action extension is simple. If you're in Safari and you're reading iMore, and your native language isn't English but French, you can tap the Share button, scroll horizontally to the Bing Translate extension, and voila, the page would translate-in-place for you.

To help keep things manageable, action extensions tell iOS their context — whether they work on text or images, form fields or something else — and iOS will only present that work in that context. So, if you select text, you won't get image action options.

You can also arrange action extensions in any order you like. Scroll to the end of the action options on the Share Sheet, tap the More button, and slide any item in the list up or down. Unlike custom share options, however, you can't toggle any of the default system actions off, but you can toggle the custom ones

Still, that means if you use the 1Password action extension to autofill your passwords all the time, you can put it into one of the first few slots. Then it's always immediately available, no scrolling required, whenever you tap the Share button.

Like plugins, action extensions don't just add more apps, they add more functionality to the system and existing apps. Say goodbye to having to leave Safari, go to 1Password, use the in-app browser, or copy the password to the clipboard and find your way back to Safari. With iOS 8, Extensibility, and action extensions, everything just works, right where you need it, right when you need it.

Custom Safari actions

There's also a special kind of action extension in iOS specifically for Safari. They're called custom Safari actions and they come in two types:

Action extensions that present it's own interface

Action extensions that presents no interface.

An example of an action extension that presents its own interface would be 1Password, which could ask you which of your 3 different Google accounts you want to use to login to YouTube.com.

An example of an action extension that currently doesn't present an interface would be Bing Translate, which, as demoed at WWDC, instantly replaces the existing text on a webpage with translated text.

Developing action extensions

Activity extensions let developers wrap up a piece of functionality from their app and make it available to iOS and other apps via the built-in Share Sheets.

Although extensions are primarily view controller based on iOS, as mentioned above, activity extensions can be view controller based, or for custom Safari extensions, they can have no view.

The difference between standard action extensions and custom Safari extensions is that only custom Safari extensions can use JavaScript integration. They get full access to the Document Object Model (DOM) and that means they can, for example, grab an image from a web page, mark it up, and then put the updated version back in place of the original.

Like with share extensions, activity extensions have activation rules to tell the system what kinds of data they can manipulate. That way, for example, if a paragraph is selected, only custom actions that can manipulate text are displayed among the options. If a picture is selected, only custom actions that can manipulate images are displayed.

Apple has several resources to help developers with action extensions:

Action extensions and security

iOS is a security- and privacy-first operating system. Adding functionality like action extensions is one thing. Adding them while maintaining a high level of security is quite another. With iOS, apps are "sandboxed" so they can only access their own data unless specific, explicit permission is given by the person using them. That's why apps need to request access to the camera roll, or why you have to tap the "Open in..." button. It makes it harder for malicious apps to do ever get onto the system and into your private data.

With iOS 8 and Extensibility, Apple keeps an app's extensions inside the app's sandbox, but allows iOS, and other apps by way of iOS, to reach out, request interface, information, and functionality. The container app can then project that interface, information, and functionality back to iOS or the host app right back.

For action extensions, the app you're sharing from is the host and the service you're sharing to is the container. For example, if you're in Safari, that the host application. If you're using an action like filling a password from 1Password or translating text from Bing, those would be the containers. Beyond security, that provides reliability — neither 1Password nor Bing in those examples would have to be running in advance, or persisting in the background, for the action extensions to be invoked.

When an action extension is called, it communicates securely through iOS to its host app for things like the authentication and password information or the translation libraries. That's then sent back to the container app so the action can complete.

Apple hasn't detailed the specifics of how all this works yet, but has said it uses similar security to the rest of iOS. Since iOS 7, Apple has done an incredible job with security and cryptography. I'm willing to bet Extensibility is enjoying something just as well thought out and just as secure.

Bottom line

Activity extensions provide incredible new functionality to iOS 8 and to iOS 8 apps. It's important to remember that this is Extensibility 1.0, and just like multitasking has, Extensibility will no doubt evolve over time. For example, it looks like 1Password can currently only fill passwords in Safari, not in web views or native interfaces in other apps.

Regardless, activity extensions mean iPhone and iPad owners will get to spend less time jumping between apps and more time getting things done within the apps they're already using. And that's a huge win.