Skip to content

MASTG-KNOW-0082: App extensions

Together with iOS 8, Apple introduced App Extensions. According to Apple App Extension Programming Guide, app extensions let apps offer custom functionality and content to users while they're interacting with other apps or the system. In order to do this, they implement specific, well scoped tasks like, for example, define what happens after the user clicks on the "Share" button and selects some app or action, provide the content for a Today widget or enable a custom keyboard.

Depending on the task, the app extension will have a particular type (and only one), the so-called extension points. Some notable ones are:

  • Custom Keyboard: replaces the iOS system keyboard with a custom keyboard for use in all apps.
  • Share: post to a sharing website or share content with others.
  • Today: also called widgets, they offer content or perform quick tasks in the Today view of Notification Center.

How do app extensions interact with other apps

There are three important elements here:

  • App extension: is the one bundled inside a containing app. Host apps interact with it.
  • Host app: is the (third-party) app that triggers the app extension of another app.
  • Containing app: is the app that contains the app extension bundled into it.

For example, the user selects text in the host app, clicks on the "Share" button and selects one "app" or action from the list. This triggers the app extension of the containing app. The app extension displays its view within the context of the host app and uses the items provided by the host app, the selected text in this case, to perform a specific task (post it on a social network, for example). See this picture from the Apple App Extension Programming Guide which pretty good summarizes this:

Security Considerations

From the security point of view it is important to note that:

  • An app extension does never communicate directly with its containing app (typically, it isn't even running while the contained app extension is running).
  • An app extension and the host app communicate via inter-process communication.
  • An app extension's containing app and the host app don't communicate at all.
  • A Today widget (and no other app extension type) can ask the system to open its containing app by calling the openURL:completionHandler: method of the NSExtensionContext class.
  • Any app extension and its containing app can access shared data in a privately defined shared container.

In addition:

  • App extensions cannot access some APIs, for example, HealthKit.
  • They cannot receive data using AirDrop but do can send data.
  • No long-running background tasks are allowed but uploads or downloads can be initiated.
  • App extensions cannot access the camera or microphone on an iOS device (except for iMessage app extensions).