[NSNull CGImage]: unrecognized selector exception when picking an asset and converting it to JPEG

243 views Asked by At

I'm using CTAssetPicker (https://github.com/chiunam/CTAssetsPickerController) to pick images, convert them to JPEG and save them in a remote storage location. So far so good, until recently (and rarely) I've started to receive weird exceptions after picking assets:

NSInvalidArgumentException  
-[NSNull CGImage]: unrecognized selector sent to instance 0x3759f3f0

This happens when calling UIImageJPEGRepresentation with an image brought back from the asset picker.

I've tried to reproduce this by sending null values to the JPEG conversion, but it's not the case. It seems as the CGImage of the UIImages I send are null, but I have no idea why it happens.

1

There are 1 answers

2
Onik IV On BEST ANSWER

The problem is you are not receiving an image. You can reproduce your error with this code:

id youThinkYourServerRetunrAnImage = [[NSNull alloc] init];
UIImage *image = youThinkYourServerRetunrAnImage;
[image CGImage];

You need to fix your request.