【发布时间】:2014-03-26 18:45:17
【问题描述】:
我有一个下载文件夹的静态文件路径,文件下载正常,但是当我下载新文件时,旧文件会被新文件替换。我想是因为静态路径。如何在我的代码中添加时间戳,以便在进行新下载时不会替换旧的?或者甚至可以为下载文件提供实际数组中的“原始”文件名?
这是我的下载代码:
-(void) Savefile {
[self.downloadfile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wooopss!" message:@"Download failed. Try Again..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
else if (data) {
[data writeToFile:@"/Users/Danny/Desktop/PDFFile/hello.pdf" atomically:NO ];
NSLog(@"Downloading file...");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Downloading" message:@"File is being downloaded..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}];
}
【问题讨论】:
标签: iphone objective-c timestamp download