我正在使用AFNetworking库下载一个压缩文件夹,文件正在下载但是当我试图解压缩该zip文件夹时,它没有打开。在mac机器上,它也不会通过双击和Archive Utility来提取。
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);
[SSZipArchive unzipFileAtPath:[filePath path] toDestination: [[filePath path] stringByDeletingLastPathComponent]];
}];
答案 0 :(得分:0)
而不是
[SSZipArchive unzipFileAtPath:[filePath path] toDestination: [[filePath path] stringByDeletingLastPathComponent]];
使用:
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath overwrite:NO password:nil error:nil]
解压缩文件
答案 1 :(得分:0)
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString * basePath =([路径计数]> 0)? [paths objectAtIndex:0]:nil;
NSString *destinationPath = [NSString stringWithFormat:@"%@/filepath",basepath]];
[SSZipArchive basePath toDestination:destinationPath overwrite:NO password:nil error:nil];
答案 2 :(得分:0)
试试这个
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"vikas.sqlite"];
NSString *outputPath = [paths objectAtIndex:0];
[SSZipArchive unzipFileAtPath:path toDestination:outputPath delegate:self];
解压缩文件将在输出路径上。