PHImageManager requestImageForAsset returns nil sometimes for iCloud photos

Roughly 10% of the time PHImageManager.defaultManager().requestImageForAsset returns nil instead of a valid UIImage after first returning a valid though "degraded" UIImage. No error or other clue that I can see is returned in the info with the nil.

This seems to happen with photos that need to be downloaded from iCloud, with iCloud Photo Library and Optimize iPad Storage both enabled. I've tried changing the options, size, etc. but nothing seems to matter.

PHCachingImageManager().requestImage(for: asset,

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

                            contentMode: .aspectFit,

                                options: options,

                          resultHandler: { (image, info) in

        if (image == nil) {

            print("Error loading image")

            print("\(info)")

        } else {

            view.image = image

        }

    });

https://stackoverflow.com/questions/31037859/phimagemanager-requestimageforasset-returns-nil-sometimes-for-icloud-photos

你可能感兴趣的:(PHImageManager requestImageForAsset returns nil sometimes for iCloud photos)