【问题标题】:Unzip file using SSZipArchive not extracting zip file使用 SSZipArchive 解压缩文件不提取 zip 文件
【发布时间】:2018-02-15 23:53:20
【问题描述】:

我正在使用 AFNetworking 库下载一个压缩文件夹,文件正在下载,但是当我尝试解压缩该 zip 文件夹时,它没有打开。在 mac 机器上,它也不会通过双击和存档实用程序进行提取。

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 会抛出什么样的错误?
  • 为目录设置属性失败:2017-09-07 10_06_53.zip/.storage。
  • 错误域=NSCocoaErrorDomain Code=4 "文件“.storage”不存在。" UserInfo={NSFilePath=2017-09-07 10_06_53.zip/.storage, NSUnderlyingError=0x600000053ce0 {Error Domain=NSPOSIXErrorDomain Code=2 "没有这样的文件或目录"}}
  • 你的目标路径是什么?我认为问题在于目标路径可能是错误的。
  • 我的源和目的路径相同,文档目录。

标签: ios objective-c macos unzip ssziparchive


【解决方案1】:

代替

[SSZipArchive unzipFileAtPath:[filePath path] toDestination: [[filePath path] stringByDeletingLastPathComponent]];

使用:

[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath overwrite:NO password:nil error:nil]

解压文件

【讨论】:

【解决方案2】:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

NSString *destinationPath = [NSString stringWithFormat:@"%@/filepath",basepath]];
[SSZipArchive basePath toDestination:destinationPath overwrite:NO password:nil error:nil];

【讨论】:

    【解决方案3】:

    试试这个

       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];
    

    解压缩文件将在输出路径上。

    【讨论】:

      猜你喜欢
      • 2016-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多