0

I have PHAsset and I want to get PHLivePhoto.

PHAsset is PHLivePhoto's asset.

I know this Function.

/// Requests a Live Photo from the given resource URLs. The result handler will be called multiple times to deliver new PHLivePhoto instances with increasingly more content. If a placeholder image is provided, the result handler will first be invoked synchronously to deliver a live photo containing only the placeholder image. Subsequent invocations of the result handler will occur on the main queue.
//  The targetSize and contentMode parameters are used to resize the live photo content if needed. If targetSize is equal to CGRectZero, content will not be resized.
//  When using this method to provide content for a PHLivePhotoView, each live photo instance delivered via the result handler should be passed to -     [PHLivePhotoView setLivePhoto:].
+ (PHLivePhotoRequestID)requestLivePhotoWithResourceFileURLs:(NSArray<NSURL *> *)fileURLs placeholderImage:(UIImage *__nullable)image targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode resultHandler:(void(^)(PHLivePhoto *__nullable livePhoto, NSDictionary *info))resultHandler;

But I don't know use.

How to convert?

Fabio Berger
  • 1,921
  • 2
  • 24
  • 29
minjoongkim
  • 121
  • 1
  • 12

2 Answers2

0

You can use this method from PHImageManager

- (PHImageRequestID)requestLivePhotoForAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(PHLivePhotoRequestOptions *)options resultHandler:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))resultHandler

Inside the resultHandler you obtain the PHLivePhoto ready to show in a PHLivePhotoView.

EXAMPLE:

[[PHImageManager defaultManager] requestLivePhotoForAsset:asset targetSize:self.contentView.frame.size contentMode:PHImageContentModeDefault options:nil resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nullable info) { self.contentView.livePhoto = livePhoto  }];
MarMass
  • 5,755
  • 1
  • 18
  • 15
0
[asset requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
PHLivePhoto *livePhoto = [contentEditingInput.livePhoto];
}];
Vikram Sinha
  • 581
  • 1
  • 10
  • 25