Type Method

requestLivePhotoWithResourceFileURLs:placeholderImage:targetSize:contentMode:resultHandler:

Asynchronously loads a Live Photo from the specified resource files.

Declaration

iOS, tvOS
+ (PHLivePhotoRequestID)requestLivePhotoWithResourceFileURLs:(NSArray<NSURL *> *)fileURLs placeholderImage:(UIImage *)image targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode resultHandler:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))resultHandler;
macOS, Mac Catalyst
+ (PHLivePhotoRequestID)requestLivePhotoWithResourceFileURLs:(NSArray<NSURL *> *)fileURLs placeholderImage:(NSImage *)image targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode resultHandler:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))resultHandler;

Parameters

fileURLs

An array of URLs containing the resource URLs that constitute a Live Photo, as obtained using the PHAssetResource class.

image

A static image to represent the Live Photo before its full content has been loaded and validated.

targetSize

The target size of Live Photo to be returned. Pass CGSizeZero to obtain the requested Live Photo at its original size.

contentMode

An option for how to fit the image to the aspect ratio of the requested size. For details, see PHLivePhoto.

resultHandler

A block to be called when image loading is complete, providing the requested Live Photo or information about the status of the request.

The block takes the following parameters:

result

The requested Live Photo object.

info

A dictionary providing information about the status of the request. See PHLivePhoto for possible keys and values.

Return Value

A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelLivePhotoRequestWithRequestID: method.

Discussion

Use this method to load Live Photo objects for display from data files previously exported from a Photos library. For example, a social networking app can use the PHAssetResource class to retrieve the data files that constitute a Live Photo in one user’s library and upload them to a server. Then, on another user’s device, the app downloads those data files and uses this method to re-create a Live Photo object for display using the PHLivePhotoView class.

This method is asynchronous. Photos loads, validates, and prepares data on a background thread, then calls your resultHandler block with a ready-to-display Live Photo object. Like the similar methods in the PHImageManager class, Photos can call your result handler block more than once—first, to provide a low-quality Live Photo object (consisting of only the static image from the image parameter), then later to provide the full motion and sound content of the Live Photo. If the PHLivePhotoInfoIsDegradedKey value in your result handler’s info dictionary is YES, Photos will call your result handler again.

This method can load a PHLivePhoto object only from the same set of files exported from a previously captured Live Photo asset. When you use this method, Photos validates that the files and their metadata can be loaded as a Live Photo. If Photos cannot load a Live Photo from the specified files, the result parameter in your result handler block is nil, and the info dictionary contains an NSError object describing the error.

See Also

Loading a Live Photo from Data Files

+ cancelLivePhotoRequestWithRequestID:

Cancels an asynchronous request

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software