44 lines
1.4 KiB
Swift
44 lines
1.4 KiB
Swift
|
import Photos
|
||
|
import UIKit
|
||
|
|
||
|
extension PHImageManager {
|
||
|
func getPhoto(for asset: PHAsset) async throws -> UIImage {
|
||
|
let options = PHImageRequestOptions()
|
||
|
options.version = .original
|
||
|
options.isSynchronous = true
|
||
|
return try await withCheckedThrowingContinuation { continuation in
|
||
|
requestImage(
|
||
|
for: asset,
|
||
|
targetSize: PHImageManagerMaximumSize,
|
||
|
contentMode: .aspectFill,
|
||
|
options: options
|
||
|
) { image, _ in
|
||
|
if let image {
|
||
|
continuation.resume(returning: image)
|
||
|
} else {
|
||
|
continuation.resume(throwing: ClientStoreError.imageNotFound)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func getVideo(for asset: PHAsset) async throws -> AVAsset {
|
||
|
let options = PHVideoRequestOptions()
|
||
|
options.version = .original
|
||
|
options.deliveryMode = .highQualityFormat
|
||
|
options.isNetworkAccessAllowed = true
|
||
|
return try await withCheckedThrowingContinuation { continuation in
|
||
|
requestAVAsset(
|
||
|
forVideo: asset,
|
||
|
options: options
|
||
|
) { avAsset, _, _ in
|
||
|
if let avAsset {
|
||
|
continuation.resume(returning: avAsset)
|
||
|
} else {
|
||
|
continuation.resume(throwing: ClientStoreError.videoNotFound)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|