1) サンプルソースコード
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- (void)downloadFile: (NSURL *)url filePath: (NSString *)filePath process:(void(^)(bool success)) process
{
if (![FileUtils fileExists:filePath]) {
[FileUtils mkdirIfNotEist:filePath];
}
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [NSURL fileURLWithPath:filePath isDirectory:YES];
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePathTmp, NSError *error) {
process(YES);
}];
[downloadTask resume];
}
documentsDirectoryURLはcustom file pathです。