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, the Photos framework provides classes that support building photo editing extensions for the Photos app. In iOS and tvOS, the Photos framework also provides direct access to the photo and video assets managed by the Photos app, including the iCloud Photo Library. Use this framework to 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 & Concepts
In iOS and tvOS, the Photos framework includes a number of features for working directly with a user’s Photos library.
Fetching objects and requesting changes. Instances of the Photos framework model classes (
PHCollectionList) 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
PHPhotoLibraryobject. 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
PHPhotoLibraryobject 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
PHCollectionListclass 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
PHImageManagerclass to request images of assets at a specified size, or AV Foundation 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
PHCachingImageManagersubclass adds bulk preloading.
Asset content editing. The
PHAssetChangeRequestclasses 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
PHAdjustmentDataobject 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, the Photos framework provides classes for use in developing photo editing extensions for use in the Photos app; however, the principal class of an extension must adopt the
PHContentEditingController protocol defined by the PhotosUI framework. For details on Photos app extensions, see App Extension Programming Guide and PhotosUI.