How to get image from PHAsset in swift iOS?

try it-

func getImageFromPHAsset(_ asset:PHAsset,size:CGSize,deliverMode:PHImageRequestOptionsDeliveryMode)->UIImage?{

        var returnImage:UIImage? = nil

        let requestImageOption = PHImageRequestOptions()

        requestImageOption.deliveryMode = deliverMode

        requestImageOption.isSynchronous = true

        let manager = PHImageManager.default()

        manager.requestImage(for: asset, targetSize:size, contentMode:PHImageContentMode.default, options: requestImageOption) { (image:UIImage?, _) in

            returnImage = image

        }

        return returnImage

    }
Back to Top