Hi All,
I'm fairly new to iPhone development and I'm trying to fetch 'Images from Server' in my application.
I'm using the following method to do this:
enter code here
- (UIImage *)imageFromURLString:(NSString *)urlString
{
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *result = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
[request release];
[self handleError:error];
UIImage *resultImage = [UIImage imageWithData:(NSData *)result];
NSLog(@"urlString: %@",urlString);
return resultImage;
}
This function does not return the expected image although I can see in debugger that NSData for the Image object has some value (in bytes)
Although, a very similar function for getting text from server works and I get expected values.
enter code here
- (NSString *)jsonFromURLString:(NSString *)urlString
{
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"GET"];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *result = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
[request release];
[self handleError:error];
NSString *resultString = [[NSString alloc] initWithData:result
encoding:NSUTF8StringEncoding];
return [resultString autorelease];
}
This method works fine.
Could someone please help me in understanding why I'm not getting the Image from server?
Thanks Neeraj