Requesting image results in "Creating an image format with an unknown type is an error"

Hello everyone.

I have a controller in which I just fetch images in user's gallery and show them. It used to work with XCode 7.3, but after upgrading it to XCode 8.0 and updating the code for Swift 3.0 compatibility, it gives me a strange and very generic error:


Creating an image format with an unknown type is an error


I am not able to figure out what is not working here. My code is the following:

        let imgManager = PHImageManager.default()
       
        let requestOptions = PHImageRequestOptions()
        requestOptions.isSynchronous = false
        requestOptions.deliveryMode = PHImageRequestOptionsDeliveryMode.fastFormat
       
        let fetchOptions = PHFetchOptions()
        fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)]
       
        let fetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: fetchOptions)
            if fetchResult.count > 0 {
                for i in 0...(fetchResult.count-1) {
                    imgManager.requestImage(for: fetchResult.object(at: i), targetSize: view.frame.size, contentMode: PHImageContentMode.aspectFit, options: requestOptions, resultHandler: { (image, _) in
                        //do some stuff
                        self.progressView.isHidden = true
                    })
                }
            } else {
                self.progressView.isHidden = true
            }


In this code I removed the image visualization code for readability. The instruction that triggers the error is the one in line 14. Any help will be very appreciated.

Replies

I can confirm I see the same error under Xcode 8, using Obj-C.


In my case I believe it occurs when making a network-disabled request for an image which is in iCloud, but not held locally.


Pseudo-code:

Request local image (network disabled) with handler:
{
     if (PHImageRequestIsInCloud key is present)
     {
          if (network is available)
          {
               // Make remote request + handle it
          }
          else
          {
               // Inform user network is needed
          }
     }
     else
     {
          // Handle local image result
     }
}


I see this error in the initial, network disabled, local image request result handler. Usually what happens is that:

1) Local result handler is called for a degraded image at thumbnail size, the image is present, all is fine.

2) I see the error: [Generic] Creating an image format with an unknown type is an error.

3) Local result handler is called a second time for a non-degraded / isInCloud result with a nil image.

4) Remote request is invoked

5) Remote result handler is called


So what appears to be happening is that PHImageManager is attempting to make a local search for a cloud-hosted image at a non-degraded size and, of course, failing to find anything. Rather than just return a nil image and an info dictionary that informs me the image is in the cloud, it appears to be trying to create the return image (presumably with no data or type!) and thus giving the generic error.


This is in PHImageManager private code, so I assume this is either an error one can ignore (Xcode 8 seems to be overly verbose in its debugging information these days), or Apple engineers will have to fix this in a future update.


Any further insight appreciated!

I forgot to mention of course - your image request is local too. By default requestImage... is local unless you set networkAccessAllowed to YES.

Thank you very much, Alex!! This helped me. Adding this

requestOptions.isNetworkAccessAllowed = true

made everything start to work again.


PS: for some reasons, I am not able to access to my account, using the same AppleID...sorry for using this new name

PS: for some reasons, I am not able to access to my account, using the same AppleID...sorry for using this new name

FYI, the fine folks at Apple Developer Program Support can help you with that.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"