1

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

3 回答 3

1

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *basePath = ([路径数] > 0) ?[路径objectAtIndex:0]:无;

NSString *destinationPath = [NSString stringWithFormat:@"%@/filepath",basepath]];
[SSZipArchive basePath toDestination:destinationPath overwrite:NO password:nil error:nil];
于 2017-09-07T11:38:33.953 回答
0

代替

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

采用:

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

解压文件

于 2017-09-07T10:47:59.420 回答
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];

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

于 2017-09-07T12:11:51.483 回答