Class

PHImageManager

Provides methods for retrieving or generating preview thumbnails and full-size image or video data associated with Photos assets.

Overview

Use these methods to fetch full-size photo assets or thumbnail images, or to retrieve AV Foundation objects for playing, exporting, and manipulating video assets.

To load image or video data:

  1. Use the PHAsset class to fetch the asset you’re interested in.

  2. Call the default() method to retrieve the shared image manager object.

  3. Use one of the methods listed in Requesting Images and Requesting Video Objects to load the asset’s image or video data.

The image manager caches the asset images and data it provides, so later requests for the same assets with similar parameters will return results more quickly.

If you need to load image data for many assets together, use the PHCachingImageManager class to “preheat” the cache by loading images you expect to need soon. For example, when populating a collection view with photo asset thumbnails, you can cache images ahead of the current scroll position.

Topics

Getting the Image Manager

class func `default`()

Returns the shared image manager object.

Requesting Video Objects

func requestAVAsset(forVideo: PHAsset, options: PHVideoRequestOptions?, resultHandler: (AVAsset?, AVAudioMix?, [AnyHashable : Any]?) -> Void)

Requests AV Foundation objects representing the video asset’s content and state, to be loaded asynchronously.

Canceling a Request

func cancelImageRequest(PHImageRequestID)

Cancels an asynchronous request

Constants

typealias PHImageRequestID

A numeric identifier for an asynchronous image request.

Image Request Identifiers

Special values for the PHImageRequestID identifier that are returned by asynchronous requests.

enum PHImageContentMode

Options for fitting an image’s aspect ratio to a requested size, used by the requestImage(for:targetSize:contentMode:options:resultHandler:) method.

Image Result Info Keys

Keys identifying information about an image loading result, used in the resultHandler block with the requestImage(for:targetSize:contentMode:options:resultHandler:) method.

Relationships

Inherits From

Conforms To

See Also

Loading Asset Content

class PHCachingImageManager

Provides methods for retrieving or generating preview thumbnails and full-size image or video data associated with Photos assets, optimized for batch preloading large numbers of assets.

class PHImageRequestOptions

A set of options affecting the delivery of still image representations of Photos assets you request from an image manager.

class PHVideoRequestOptions

A set of options affecting the delivery of video asset data that you request from an image manager.

class PHLivePhotoRequestOptions

A set of options affecting the delivery of Live Photo assets you request from an image manager.

class PHLivePhoto

A displayable representation of a Live Photo—a picture that includes motion and sound from the moments just before and after its capture.