Class

PHAssetCreationRequest

A request to create a new Photos asset from underlying data resources, for use in a photo library change block.

Declaration

class PHAssetCreationRequest : PHAssetChangeRequest

Overview

A PHAssetCreationRequest object, used within a photo library change block, constructs a new photo or video asset from data resources, and adds it to the Photos library. This class works in terms of the raw data resources that together form an asset, so you can use it together with the PHAssetResource class to perform a complete copy (or backup and restore) of an asset’s underlying resources. To instead simply create a new asset from an image object, image file, or video file, see the superclass PHAssetChangeRequest.

To create a new asset from data resources, first start a change block using the shared PHPhotoLibrary method performChanges(_:completionHandler:) or performChangesAndWait(_:). Then, within the change block:

  1. Within the change block, create a new asset creation request with the forAsset() method.

  2. Add image, video, or data resources using the methods listed in Providing Data Resources for the New Asset.

  3. (Optional.) Set metadata for the new asset using methods and properties of the superclass PHAssetChangeRequest.

After Photos runs the change block and calls your completion handler, the new asset is created in the Photos library.

If you instantiate or use this class outside a photo library change block, Photos throws an exception. For details on change blocks, see PHPhotoLibrary.

Topics

Requesting Asset Creation

class func forAsset() -> Self

Creates a request for adding a new asset to the Photos library using asset resources.

Preflighting a Request

class func supportsAssetResourceTypes([NSNumber]) -> Bool

Returns a Boolean value indicating whether Photos supports creating an asset with the specified combination of resource types.

Providing Data Resources for the New Asset

func addResource(with: PHAssetResourceType, data: Data, options: PHAssetResourceCreationOptions?)

Adds a data resource to the asset being created, using the specified data.

func addResource(with: PHAssetResourceType, fileURL: URL, options: PHAssetResourceCreationOptions?)

Adds a data resource to the asset being created, using the file at the specified URL.

Relationships

Conforms To

See Also

Asset Resource Management

class PHAssetResource

An underlying data resource associated with a photo, video, or Live Photo asset in the Photos library.

class PHAssetResourceCreationOptions

A set of options affecting the creation of a new Photos asset from underlying resources.

class PHAssetResourceManager

A resource manager for the data storage underlying a Photos asset.

class PHAssetResourceRequestOptions

A set of options affecting the delivery of underlying asset data that you request from the asset resource manager.