Contents

writeData(for:toFile:options:completionHandler:)

Requests the underlying data for the specified asset resource, to be asynchronously written to a local file.

Declaration

func writeData(for resource: PHAssetResource, toFile fileURL: URL, options: PHAssetResourceRequestOptions?, completionHandler: @escaping  @Sendable ((any Error)?) -> Void)
func writeData(for resource: PHAssetResource, toFile fileURL: URL, options: PHAssetResourceRequestOptions?) async throws

Parameters

  • resource:

    The asset resource for which to request data.

  • fileURL:

    A URL identifying the local filename at which to write the asset resource’s data.

  • options:

    Options specifying how Photos should handle the request and notify your app of progress. For details, see Phassetresourcerequestoptions.

  • completionHandler:

    A block that photos calls after the request has been fulfilled or has failed.

    The block takes a single parameter:

    error

    If the request has failed, an NSError object describing the failure; otherwise nil.

Discussion

When you call this method, Photos begins asynchronously reading the underlying data for the asset resource. Depending on the options you specify and the current state of the asset, Photos may download asset data from the network.

While reading (or downloading) asset resource data, Photos progressively writes the data into the specified file. After writing all of the data, or if an error prevents reading all of the data, Photos calls your completionHandler block.

See Also

Requesting Resources