Work with image and video assets managed by the Photos app, including those from iCloud Photo Library and Live Photos. Fetch and cache full-sized assets or thumbnails asynchronously, revise content, and sync revisions to multiple devices.
- iOS 8.0+
- macOS 10.11+
- tvOS 10.0+
In iOS and macOS, PhotoKit provides classes that support building photo editing extensions for the Photos app. In iOS and tvOS, PhotoKit also provides direct access to the photo and video assets managed by the Photos app, including the iCloud Photo Library. Retrieve assets for display and playback, edit their image or video content, or work with collections of assets such as albums, moments, and iCloud Shared Albums.
Features and Concepts
PhotoKit includes a number of features for working directly with a user’s Photos library.
Fetching objects and requesting changes. Instances of the model classes (
PHCollection) represent the items a user works with in the Photos app: assets (images, videos, and Live Photos), collections of assets (such as albums or moments), and lists of collections (such as album folders or moment clusters). These objects are read-only, immutable, and contain only metadata.
You work with assets and collections by fetching those that you’re interested in and then using those objects to fetch the data you need to work with. To make changes, you create change request objects and explicitly commit them to the shared
PHPhotoobject. This architecture makes it easy, safe, and efficient to work with the same assets from multiple threads or multiple apps and app extensions.
Change observing. Use the shared
PHPhotoobject to register a change handler for the assets and collections you fetch. Photos tells your app whenever another app or device changes the content or metadata of an asset or the list of assets in a collection.
PHChangeobjects provide information about object state before and after each change with semantics that make it easy to update a collection view or similar interface.
Support for Photos app features. Use the
PHCollectionclass to find assets corresponding to the Moments hierarchy in the Photos App. Use the
PHAssetclass to identify burst photos, panoramic photos, and high-frame-rate videos. When the iCloud Photo Library is enabled, assets and collections in the Photos framework reflect content available across all devices on the same iCloud account.
Asset and thumbnail loading and caching. Use the
PHImageclass to request images of assets at a specified size, or AVFoundation objects to work with video assets. The Photos framework automatically downloads or generates images to your specification, caching them for quick reuse. For faster performance with large numbers of assets—for example, when populating a collection view with thumbnails—the
PHCachingsubclass adds bulk preloading.
Asset content editing. The
PHAssetclasses define methods to request photo or video content for editing and to commit your edits to the photo library. To support continuity of editing between different apps and extensions, Photos keeps the current and previous versions of each asset, along a with
PHAdjustmentobject that describes the last edit. If your app supports the adjustment data from a previous edit, you can allow the user to revert or alter the edit.
In iOS and macOS, PhotoKit provides classes for use in developing photo editing extensions for use in the Photos app. The principal class of an extension must adopt the
PHContent protocol. For details on Photos app extensions, see App Extension Programming Guide.
Creating Photo Editing Extensions
In iOS or macOS, you adopt the
PHContent protocol to create an app extension that adds to the photo editing options and capabilities in the Photos app. Creating such an extension also requires using the following classes from the Photos framework:
Displaying Live Photos
PHLive class provides a way to display Live Photos—pictures, taken on compatible hardware, that include motion and sound from the moments just before and after their capture. A Live Photo view provides the same interactive playback features found in the Photos app.
In iOS and tvOS, you can fetch Live Photo objects to display in a Live Photo view with the
PHLive class in the Photos framework. In macOS, the
PHLive class provides access to Live Photos being edited in a photo editing extension for the Photos app.
To display Live Photo content on the web, use the LivePhotosKit JS framework.