Skip to content

Instantly share code, notes, and snippets.

@an-indya
Created May 13, 2018 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an-indya/91d8a2e15b98b873ca1560b4a016bde7 to your computer and use it in GitHub Desktop.
Save an-indya/91d8a2e15b98b873ca1560b4a016bde7 to your computer and use it in GitHub Desktop.
- (void) downloadImage {
NSString *imageUrl = @"http://images.apple.com/v/watch/c/images/nav_sport_large.jpg";
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil ];
NSURLSessionTask *downloadTask = [session downloadTaskWithURL:[NSURL URLWithString:imageUrl]];
[downloadTask resume];
}
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask
didFinishDownloadingToURL:(NSURL *)location
{
// use code above from completion handler
}
//For progress indication
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
{
NSLog(@"%f / %f", (double)totalBytesWritten,
(double)totalBytesExpectedToWrite);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment