我下载了一个文件:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:episode.enclosure_url]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *fileExtension = [episode.enclosure_url pathExtension];
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:[episode.enclosure_urlAlphanumericOnly stringByAppendingString:[NSString stringWithFormat:@".%@", fileExtension]]];
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:path shouldResume:YES];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// COMPLETION BLOCK
NSLog(@"Successfully downloaded file to %@", path);
downloadInfo.filePath = path;
downloadInfo.isComplete = @YES;
// save context
NSError *error;
BOOL success = [self.workerContext save:&error];
if (!success || error) {
NSLog(@"%@", error.localizedDescription);
}
…
成功完成块触发,记录:
Successfully downloaded file to /Users/myName/Library/Application Support/iPhone Simulator/7.1-64/Applications/D629F52C-E299-42C7-BF7E-DF8D096529C7/Documents/httppodcastdownloadnprorganonnprpodcastspodcast13308789280npr308789280mp3.mp3
然后我检查文件的存在:
if ([[NSFileManager defaultManager] fileExistsAtPath:[localUrl path]]) {
…
找不到该文件。我也没有在Finder中看到任何新文件。
为什么AFDownloadRequestOperation
表示下载成功,但文件似乎不存在?或者,具有恢复功能的下载方式是什么?感谢