Instance Method

requestImageDataAndOrientation(for:options:resultHandler:)

Requests the largest represented image as data bytes and EXIF orientation for the specified asset.

Declaration

func requestImageDataAndOrientation(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.

If PHImageRequestOptionsVersion.current is requested and the asset has adjustments, the largest rendered image data is returned. In all other cases, the original image data is returned.

For further details, see PHImageRequestOptions.

resultHandler

A block called, exactly once, 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 uniform type identifier for the image.

orientation

The EXIF orientation for the image, as a CGImagePropertyOrientation. For iOS or tvOS, convert this orientation to a UIImage.Orientation.

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