ios - 使用SSZipArchive解压缩文件而不解压缩zip文件

标签 ios objective-c macos unzip ssziparchive

我正在使用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]];
}];

最佳答案

尝试这个

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

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

关于ios - 使用SSZipArchive解压缩文件而不解压缩zip文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46093018/

相关文章:

xcode - 如何强制应用程序以隐藏模式启动? (Mac 登录应用程序)

ruby - 在两个不同操作系统之间开发的最佳方式

c++ - 如何让 OpenGL 在 OSX 上运行

ios - 函数签名特化在 swift 中崩溃

ios - swift - 尝试用委托(delegate)更新 UILabel

ios - 本地化 APN 警报中的时间戳

ios - 在 Swift 中使用 UITableView 以编程方式切换 View

ios - 无法执行转接

Facebook 问题的 iOS 社交框架

ios - Objective-C 如何使用 header 中的嵌套字典将数据发送到 Http Post 请求