Class

PHImageManager

An object that facilitates retrieving or generating preview thumbnails and asset data.

Declaration

class PHImageManager : NSObject

Overview

Use these methods to fetch full-size photo assets or thumbnail images, or to retrieve AVFoundation 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`() -> PHImageManager

Returns the shared image manager object.

Canceling a Request

func cancelImageRequest(PHImageRequestID)

Cancels an asynchronous request

typealias PHImageRequestID

A numeric identifier for an asynchronous image request.

let PHInvalidImageRequestID: PHImageRequestID

A special value provided for asynchronous image requests that cannot be canceled.

Constants

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 image request methods.

Relationships

Inherits From

Conforms To

See Also

Asset Loading

Loading and Caching Assets and Thumbnails

Request image, video, or Live Photos content, and cache for quick reuse.

class PHCachingImageManager

An object that facilitates retrieving or generating preview thumbnails, 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.