iOS Developer Library — Prerelease

Developer

Foundation Framework Reference NSExtensionRequestHandling Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSExtensionRequestHandling

The NSExtensionRequestHandling protocol provides a life cycle hook into an app extension. An extension’s principal object can implement this protocol and use beginRequestWithExtensionContext: to keep track of the request from a host app.

  • Tells the extension to prepare for a host app’s request.

    Declaration

    Swift

    func beginRequestWithExtensionContext(_ context: NSExtensionContext)

    Objective-C

    - (void)beginRequestWithExtensionContext:(NSExtensionContext * _Nonnull)context

    Parameters

    context

    An NSExtensionContext object that represents the context in which the host app makes the request. Typically, the context contains data that the extension can work on.

    Discussion

    An extension prepares for a host app’s request by getting the context passed in this method and requesting related data items, if appropriate. This method is received after the extension is initialized, but before the principal object is asked to do anything with the context. For example, if the principal object is a view controller, it receives this message before loadView is called. After an extension receives this message, the extensionContext property of the view controller returns a nonnil value.

    If your subclass conforms to this protocol and overrides beginRequestWithExtensionContext:, the subclass is expected to call [super beginRequestWithExtensionContext:].

    Availability

    Available in iOS 8.0 and later.