Contents

NSItemProvider

An item provider for conveying data or a file between processes during drag-and-drop or copy-and-paste activities, or from a host app to an app extension.

Declaration

class NSItemProvider

Overview

Starting in iOS 11, item providers play a central role in drag and drop, and in copy and paste. They continue to play a role with app extensions.

The system uses an internal queue when calling the completion blocks for the NSItemProvider class. When using an item provider with drag and drop, ensure that UI updates take place on the main queue as follows:

DispatchQueue.main.async {
    // Work that impacts the user interface.
}

App extension support

An app extension typically encounters item providers when examining the attachments property of an NSExtensionItem object. During that examination, the extension can use the hasItemConformingToTypeIdentifier(_:) method to look for data that it recognizes. Item providers use Uniform Type Identifiers values to identify the data they contain. After finding a type of data that your extension can use, it calls the loadItem(forTypeIdentifier:options:completionHandler:) method to load the actual data, which is delivered to the provided completion handler.

You can create item providers to vend data to another process. An extension that modifies an original data item can create a new NSItemProvider object to send back to the host app. When creating data items, you specify your data object and the type of that object. You can optionally use the previewImageHandler property to generate a preview image for your data.

A single item provider may use custom blocks to provide its data in many different formats. When configuring an item provider, use the registerItem(forTypeIdentifier:loadHandler:) method to register your blocks and the formats each one supports. When a client requests data in a particular format, the item provider executes the corresponding block, which is then responsible for coercing the data to the appropriate type and returning it to the client.

Topics

Creating an item provider

Configuring the provider

Querying the provider’s contents

Loading the provider’s contents

Loading a preview image

Registering CloudKit shares

Registering content types

Registering data

Registering files

Registering group activities

Registering objects

Getting the provider’s frame

Constants

Initializers

See Also

Attachments