Я использую SSZipArchive
. После загрузки файла я хочу разархивировать архив и показать изображение. Но код не работает. Как это исправить?Как распаковать файл?
загрузить файл
-(IBAction) downloadButton:(id)sender
{
if (_HighScore == 2) {
_url1 =[NSURL URLWithString:@"link2.zip"];
_downloadTask1 = [_session downloadTaskWithURL:_url1];
[_downloadTask1 resume];
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{
if (downloadTask == _downloadTask1) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSURL *documentsFolder = [paths objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *newLocation = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/2.zip", documentsFolder]];
NSError *error;
[fileManager copyItemAtURL:location toURL:newLocation error:&error];
NSLog(@"file%@", newLocation.absoluteString);
}
разархивировать файл
_documentsDirectory1 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
_zipPath1 = [_documentsDirectory1 stringByAppendingPathComponent:@"2.zip"];
_destinationPath1 = [_documentsDirectory1 stringByAppendingPathComponent:@"file://%@/2.zip"];
_fileExists1 = [[NSFileManager defaultManager] fileExistsAtPath:_zipPath1 isDirectory:false];
if([SSZipArchive unzipFileAtPath:_zipPath1 toDestination:_destinationPath1] != NO) {
NSLog(@"Dilip Success");
}else{
NSLog(@"Dilip Error");
}
UPD
-(IBAction) downloadButton:(id)sender
{
if (_HighScore == 2) {
_url1 =[NSURL URLWithString:@"link2.zip"];
_downloadTask1 = [_session downloadTaskWithURL:_url1];
[_downloadTask1 resume];
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{
if (downloadTask == _downloadTask1) {
_documentsDirectory1 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
_zipPath1 = [_documentsDirectory1 stringByAppendingPathComponent:@"2.zip"];
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (downloadTask == _downloadTask1) { NSData *urlData1 = [NSData dataWithContentsOfURL:_url1]; [urlData1 writeToFile:_zipPath1 atomically:YES];}
});
}
между Я заметил, что '[_documentsDirectory1 stringByAppendingPathComponent: @ "/ PDFFolder"]' вы добавляете '/' на самом деле, метод 'stringByAppendingPathComponent' добавляет'/'U не нужно указывать его просто изменить это для '_filePath1 = [_documentsDirectory1 stringByAppendingPathComponent: @" PDFFolder "];' просто использовать 'PDFFolder', заменить его для всех –
не работает ... Я обновляю вопрос. пожалуйста, проверьте. – User
проверили пути и файл zip для загрузки, указанный в указанной папке ..? а также способ загрузки изображения, чтобы изображение отображалось на пути, пока вы загружаете изображение 'UIImage * image1 = [UIImage imageWithContentsOfFile: workSpacePath1];' –