Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

swift

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)

like image 324
K.Wu Avatar asked Apr 16 '18 20:04

K.Wu


1 Answers

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)
        }
}
like image 59
a.masri Avatar answered Oct 29 '22 03:10

a.masri