Iphone – Missing Data for Image

iphone

I am loading an image from the internet using the following code:

NSURL *URL = [NSURL URLWithString:urlToImage];
NSData *data = [NSData dataWithContentsOfURL:URL options:0 error:&err]];
self.img = [[UIImage alloc] initWithData:data];

After the above:

self.img == nil, err == nil

No error, or no img.

I am suspecting that the data coming from the server is being truncated. THe data variable ends up being 850b but the image is 20K.

So, is there any reason data would be truncated?

Thanks in advance

Best Answer

You should look and see what's in those 850 bytes. Then you could see if it's really the start of an image or maybe it's the text of an HTTP error message.

Do something like:

char* bytes = [data bytes];

and then in the debugger, do Variables View->View Memory In Browser to see what's in bytes.