Created
May 13, 2018 03:25
-
-
Save an-indya/fa956f36825ee5c8a330fbdb32742806 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
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; | |
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; | |
NSURL *URL = [NSURL URLWithString:@"http://example.com/download.zip"]; | |
NSURLRequest *request = [NSURLRequest requestWithURL:URL]; | |
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) { | |
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; | |
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]]; | |
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) { | |
NSLog(@"File downloaded to: %@", filePath); | |
}]; | |
[downloadTask resume]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment