Thomas Valenzuela
Thomas Valenzuela

Reputation: 101

requestImageData was deprecated in iOS 13

I am getting this depreciation message in my my project:

requestImageData(for:options:resultHandler:) was deprecated in iOS 13

What is the most updated method to fix this?

func convertImageFromAsset(asset: PHAsset) -> UIImage? {
    
    var img: UIImage?
    let manager = PHImageManager.default()
    let options = PHImageRequestOptions()
    options.version = .original
    options.isSynchronous = true
    manager.requestImageData(for: asset, options: options) { data, _, _, _ in
        
        if let data = data {
            img = UIImage(data: data)
        }
    }
    return img
}

Upvotes: 9

Views: 1987

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 88032

As it says in the documentation, you should use requestImageDataAndOrientation - it has the same API, I think this is just a renaming done for better readability.

manager.requestImageDataAndOrientation(for: asset, options: options) { data, _, _, _ in
    if let data = data {
        img = UIImage(data: data)
    }
}

Upvotes: 10

Related Questions