PHImageManager throws "First stage of an opportunistic image request returned a non-table format image, this is not fatal, but it is unexpected"

I am using PHImageCachingManager to get images for PHAsset. I need to use the opportunistic mode so that first the low resolution image available gets loaded and then as the full resolution becomes available, it gets loaded.

For some reason I keep getting the following warning and my low resolution image doesn't load. Image only loads when the highest resolution gets fetched (from iCloud).

The warning:

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

What am I doing wrong?

    let imageRequestOptions = PHImageRequestOptions()
    imageRequestOptions.isNetworkAccessAllowed = true
    imageRequestOptions.deliveryMode = .opportunistic
    let imageCachingManager = PHCachingImageManager()

    imageCachingManager.requestImage(for: asset , targetSize: PHImageManagerMaximumSize, contentMode: .aspectFill, options: imageRequestOptions) { (image, infoDict) in
        DispatchQueue.main.async {
            if self.myImageView.identifierTag == asset.localIdentifier {
                self.myImageView.image = image
            }
        }
    }

Upvotes: 0

Views: 1093

Answers (2)

wangliang
wangliang

Reputation: 1

PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init];
option.synchronous = YES;
``
将synchronous 属性设置为YES

Upvotes: -1

El Tomato
El Tomato

Reputation: 6707

imageCachingManager.requestImage(for: asset , targetSize: PHImageManagerMaximumSize, contentMode: .aspectFill, options: imageRequestOptions) { (image, infoDict) in
    DispatchQueue.main.async {
        if self.myImageView.identifierTag == asset.localIdentifier {
            self.myImageView.image = image
        }
    }
}

You are setting the maximum size available as an image size. Change

targetSize: PHImageManagerMaximumSize

to

targetSize: CGSize(width: asset.pixelWidth, height: asset.pixelHeight)

or specify the image size like CGSize(with: 150, height: 150) unless you want to explode your device due to memory depletion.

Upvotes: 5

Related Questions