UIActivity without reading a stored file into into memory?

66 views Asked by At

My app writes huge images (billions of pixels).

The image is too large to read as a UIImage or as Data.

Typically, when I share images with an activity controller, I do this:

var data: Data
data = ...
activityViewController = UIActivityViewController(activityItems: [data], applicationActivities: [purchaseCanvasPrintActivity])

Is it possible to pass a URL or something that points to the stored file than having to be allocated in a Data object or accomplish this with a custom UIActivity?

1

There are 1 answers

20
Alexander On

From the docs (emphasis mine):

init(activityItems:applicationActivities:)

...

activityItems

The array of data objects on which to perform the activity. The type of objects in the array is variable and dependent on the data your application manages. For example, the data might consist of one or more string or image objects representing the currently selected content.

Instead of actual data objects, the objects in this array can be objects that adopt the UIActivityItemSource protocol, such as UIActivityItemProvider objects. Source and provider objects act as proxies for the corresponding data in situations where you do not want to provide that data until it is needed. Note that you should not reuse an activity view controller object that includes a UIActivityItemProvider object in its activityItems array.

Try implementing your own subclass of UIActivityItemProvider to provide the data on-demand.