Instance Method

requestImageData(for:options:resultHandler:)

Requests full-sized image data for the specified asset.

Declaration

iOS, tvOS
func requestImageData(for asset: PHAsset, options: PHImageRequestOptions?, resultHandler: @escaping (Data?, String?, UIImage.Orientation, [AnyHashable : Any]?) -> Void) -> PHImageRequestID
macOS
func requestImageData(for asset: PHAsset, options: PHImageRequestOptions?, resultHandler: @escaping (Data?, String?, CGImagePropertyOrientation, [AnyHashable : Any]?) -> Void) -> PHImageRequestID

Parameters

asset

The asset for which to load image data.

options

Options specifying how Photos should handle the request, format the requested image, and notify your app of progress or errors. For details, see PHImageRequestOptions.

resultHandler

A block to be called when image loading is complete, providing the requested image or information about the status of the request.

The block takes the following parameters:

imageData

The requested image.

dataUTI

The requested image.

orientation

The intended display orientation for the image.

info

A dictionary providing information about the status of the request. See Image Result Info Keys for possible keys and values.

Return Value

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelImageRequest(_:) method.

Discussion

When you call this method, Photos loads the largest available representation of the image asset, then calls your resultHandler block to provide the requested data. Depending on the options you specify and the current state of the asset, Photos may download asset data from the network.

By default, this method executes asynchronously. If you call it from a background thread you may change the isSynchronous property of the options parameter to true to block the calling thread until either the requested image is ready or an error occurs, at which time Photos calls your result handler. This method ignores the deliveryMode option—Photos calls your result handler block exactly once.

If the version option is set to PHImageRequestOptionsVersion.current, Photos provides rendered image data, including the results of any edits that have been made to the asset content. Otherwise, Photos provides the originally captured image data for the asset.

See Also

Requesting Images