0

I am having following code for getting image from the web:

 NSURL *ImageURL = [NSURL URLWithString:@"http://url/image.jpg"];

 NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL];

I am getting following exception:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithCapacity:]: capacity (4294967295) is ridiculous'

If i remove the second line of nsdata then exception is not occurring .Please give me the solution.

V-Xtreme
  • 7,230
  • 9
  • 39
  • 79

2 Answers2

0

Your url path may have space. So use like this

NSString *url=@"http://url/image.jpg";

url=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *data=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:url]];
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
Senthilkumar
  • 2,471
  • 4
  • 30
  • 50
0

Try this code piece from another SO question, mbm30075's answer as long as your image's size is small. If not, in order for the UI to be interactive, use asynchronous connection to download the image first with NSURLConnection

Community
  • 1
  • 1
Eren Beşel
  • 1,047
  • 8
  • 16