K.Wu
K.Wu

Reputation: 3633

Getting a non-fatal but unexpected error while converting a PHAsset to a UIImage

I am using this code to convert a PHAsset to a full size UIImage:

func getOriginalAsset(asset: PHAsset, onComplete: @escaping (UIImage?, [AnyHashable: Any]?) -> ()) {
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    option.isNetworkAccessAllowed = true

    manager.requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: option) { (image, info) in
        onComplete(image, info)
    }
}

However, I'm getting this warning from the console every time I try to run this code:

[ImageManager] First stage of an opportunistic image request returned a non-table format image, this is not fatal, but it is unexpected

Question

  1. Why do I get this warning?

  2. How do I resolve this?

Update

Everything works fine when I run this code despite the warning. I just can't stand any warnings/errors in my app (Maybe I'll have to learn to accept it sooner or later)

Upvotes: 5

Views: 1737

Answers (1)

a.masri
a.masri

Reputation: 2469

try use this code , I'm add isSynchronous = true you can read this document isSynchronous

I will explain to you the cause of the problem quickly This problem occurs because the opatation is shown until the end of the image and you request large size images may take time so you should be Thread in the waiting period until the process of fetching the image

func getOriginalAsset(asset: PHAsset, onComplete: @escaping (UIImage?, [AnyHashable: Any]?) -> ()) {
        let manager = PHImageManager.default()
        let option = PHImageRequestOptions()
        option.isNetworkAccessAllowed = true
        option.isSynchronous = true 
        manager.requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: option) { (image, info) in
            onComplete(image, info)
        }
}

Upvotes: 10

Related Questions