Reputation: 950
I am Using UIImage View and add Image there like this code
NSURL *imageURL = [NSURL URLWithString:@"http://d1mxp0yvealdwc.cloudfront.net/e92c939d-e83b-4592-b367-327fa67339fb/1001 123.jpg"];
NSLog(@"imge %@",imageURL);
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
NSLog(@"imge %@",imageData);
UIImage *image = [UIImage imageWithData:imageData];
NSLog(@"imge %@",image);
[image_view setImage:image];
but all of nslog show null Actually there is problem in url but this show image on web so please tell me what's the problem here.
Upvotes: 1
Views: 6412
Reputation: 171
Try Following Code :
NSURL *aURL = [NSURL URLWithString:[@"http://d1mxp0yvealdwc.cloudfront.net/e92c939d-e83b-4592-b367-327fa67339fb/1001%20123.jpg" stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
UIImage *aImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:aURL]];
This is working fine...!!!
Upvotes: 5
Reputation: 3061
Your URL string has a space which needs to be replaced with percent escapes.
Either use this -
NSURL *imageURL = [NSURL URLWithString:@"http://d1mxp0yvealdwc.cloudfront.net/e92c939d-e83b-4592-b367-327fa67339fb/1001%20123.jpg"];
Or
NSString *imageUrlString = @"http://d1mxp0yvealdwc.cloudfront.net/e92c939d-e83b-4592-b367-327fa67339fb/1001 123.jpg";
NSString *encodedImageUrlString = [imageUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *imageURL = [NSURL URLWithString: encodedImageUrlString];
Upvotes: 2