Created
May 13, 2018 03:23
-
-
Save an-indya/91d8a2e15b98b873ca1560b4a016bde7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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