Download image
It is an easy snippet for to download image from the web
NSString *imageUrl = @"http://someHost.com/image.jpg";
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session =
[NSURLSession sessionWithConfiguration:sessionConfig
delegate:self delegateQueue:nil];
NSURLSessionDownloadTask *getImageTask =
[session downloadTaskWithURL:[NSURL URLWithString:imageUrl]
completionHandler:^(NSURL *location, NSURLResponse *response,
NSError *error) {
downloadedImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:location]];
dispatch_async(dispatch_get_main_queue(), ^{ // do stuff with
//_image is an imageVIew
_image.image = downloadedImage;
}); }];
[getImageTask resume];
Written by DiegoCaridei
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Objective-c
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#