Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11: [ImageManager] Unable to load image data

After update to iOS 11, photo assets now load slowly and I get this message in console:

[ImageManager] Unable to load image data, /var/mobile/Media/DCIM/103APPLE/IMG_3064.JPG

I use static function to load image:

class func getAssetImage(asset: PHAsset, size: CGSize = CGSize.zero) -> UIImage? {
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    option.isSynchronous = true

    var assetImage: UIImage!
    var scaleSize = size
    if size == CGSize.zero {
        scaleSize = CGSize(width: asset.pixelWidth, height: asset.pixelHeight)
    }

    manager.requestImage(for: asset, targetSize: scaleSize, contentMode: .aspectFit, options: option) { (image, nil) in
        if let image = image {
            assetImage = image
        }
    }
    if assetImage == nil {
        manager.requestImageData(for: asset, options: option, resultHandler: { (data, _, orientation, _) in
            if let data = data {
                if let image = UIImage.init(data: data) {
                    assetImage = image
                }
            }
        })
    }
    return assetImage
}

Request image for asset usually always succeeds, but it prints this message. If I use requestImageData function only, there is no such message, but photos made with Apple camera lose their orientation and I get even more issues while loading big amount of images (I use image slideshow in my app).

Apple always sucks when it comes to updates, maybe someone got a solution how to fix this? It even fails to load an asset, when there is a big list of them in user camera. Switching to requestImageData is not an option for me as it brings nil data frequently now.

I would like to point out, that I call this function only once. It is not used in UITableView etc. I use other code for thumbs with globally initialised manager and options, so assets are definitely not nil or etc. I call this function only when user clicks at certain thumb. When gallery has like 5000 photos, maybe connection to assets is just overloaded and later it can't handle request and crashes? So many questions.

like image 980
Bio-Matic Avatar asked Sep 23 '17 08:09

Bio-Matic


3 Answers

Hey I was having the warning as well and here is what worked for me.

Replacing CGSize(width: asset.pixelWidth, height: asset.pixelHeight) by PHImageManagerMaximumSize in requestImage call removed the warning log 🎉

Hope this helps,

like image 185
sachadso Avatar answered Nov 01 '22 19:11

sachadso


I had the same problem. Though this did not completely solve it, but it definitely helped.

option.isNetworkAccessAllowed = true

This helps only on the devices where Optimise iPhone Storage option for Photos app has been turned on.

like image 6
Mitul Jindal Avatar answered Nov 01 '22 18:11

Mitul Jindal


Your code has some serious issues. You are saying .isSynchronous = true without stepping into a background thread to do the fetch. That is illegal and is what is causing the slowness. Plus, you are asking for a targetSize without also saying .resizeMode = .exact, which means you are getting much bigger images than you are asking for.

However, the warning you're seeing is irrelevant and can be ignored. It in no way signals a failure of image delivery; it seems to be just some internal message that has trickled up to the console by mistake.

like image 2
matt Avatar answered Nov 01 '22 19:11

matt