Ios 使用SSZipArchive解压文件,但不解压zip文件
我正在使用AFNetworking library下载一个压缩文件夹,文件正在下载,但当我试图解压缩该压缩文件夹时,它并没有打开。在mac机器上,它也不是通过双击和存档实用程序提取的Ios 使用SSZipArchive解压文件,但不解压zip文件,ios,objective-c,macos,unzip,ssziparchive,Ios,Objective C,Macos,Unzip,Ssziparchive,我正在使用AFNetworking library下载一个压缩文件夹,文件正在下载,但当我试图解压缩该压缩文件夹时,它并没有打开。在mac机器上,它也不是通过双击和存档实用程序提取的 NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response
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]];
}];
而不是
[SSZipArchive unzipFileAtPath:[filePath path] toDestination: [[filePath path] stringByDeletingLastPathComponent]];
使用:
解压缩文件NSArray*path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString*basePath=([路径计数]>0)?[路径对象索引:0]:无
NSString *destinationPath = [NSString stringWithFormat:@"%@/filepath",basepath]];
[SSZipArchive basePath toDestination:destinationPath overwrite:NO password:nil error:nil];
试试这个
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];
解压文件将位于输出路径上。SSZipArchive中会出现什么类型的错误?
SSZipArchive
?为目录设置属性失败:2017-09-07 10_06_53.zip/.storage.error Domain=nscocaerordomain code=4“文件”.storage“不存在”。UserInfo={NSFilePath=2017-09-07 10_06_53.zip/.storage,NSUnderlyingError=0x60000053ce0{Error Domain=NSPOSIXErrorDomain Code=2“没有这样的文件或目录”}您的目标路径是什么?我想目标路径可能有问题。我的源路径和目标路径相同,文档目录。不使用此代码也会出现相同的错误。
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];