Get the local file path of a PHAsset
Use content editing input:
asset.requestContentEditingInput(with: PHContentEditingInputRequestOptions()) { (input, _) in let url = input.fullSizeImageURL}
Make sure that the asset is PHAssetMediaType.Image
or otherwise it may crash when unpacking an optional.
func getImagesFromAsset(anAsset: PHAsset) { PHImageManager.default().requestImage(for: anAsset, targetSize: CGSize(width: 600, height: 600), contentMode: .aspectFill, options: nil, resultHandler: { (image, info) in //resultHandler have info ([AnyHashable: Any]) print(info!["PHImageFileURLKey"]) if let img = image { self.imgv.image = img } })}
this might helppaste this in you CellForRowAt method and pass the PHAsset in argument.
PHAsset *asset = YOUR_ASSET;PHImageManager *manager = [PHImageManager defaultManager];PHImageRequestOptions *options = [PHImageRequestOptions new];options.synchronous = YES;options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;options.resizeMode = PHImageRequestOptionsResizeModeNone;options.networkAccessAllowed = NO;[manager requestImageForAsset:YOUR_ASSET targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage *resultImage, NSDictionary *info){ NSURL *filePath = [info valueForKeyPath:@"PHImageFileURLKey"]}];