Objective c 如何找到正在使用ZipArchive解压的文件?

Objective c 如何找到正在使用ZipArchive解压的文件?,objective-c,ios7,unzip,ziparchive,dispatch-async,Objective C,Ios7,Unzip,Ziparchive,Dispatch Async,ZipArchive无法找到我试图解压缩的文件。我做错了什么?我试图在dispatch\u async中完成所有这些,这是我的问题吗 我的日志中出现了“找不到zip文件”。当我在我的应用程序数据文件中查找应该创建的目录时,找不到它。zip文件是如何存在的 这里有一个链接到一个非常类似于我正在尝试做的。我还添加了所需的库 为每个请求编辑代码,包括错误处理: NSLog(@"Got the data!"); NSArray *paths = NSSearchPathForDirect

ZipArchive无法找到我试图解压缩的文件。我做错了什么?我试图在dispatch\u async中完成所有这些,这是我的问题吗

我的日志中出现了“找不到zip文件”。当我在我的应用程序数据文件中查找应该创建的目录时,找不到它。zip文件是如何存在的

这里有一个链接到一个非常类似于我正在尝试做的。我还添加了所需的库

为每个请求编辑代码,包括错误处理:

    NSLog(@"Got the data!");
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *path = [paths  objectAtIndex:0];

    //Save the data
    NSLog(@"Saving");
    NSString *dataPath = [path stringByAppendingPathComponent:@"TKAPlacesImages.zip"];
    dataPath = [dataPath stringByStandardizingPath];

    NSError *error = nil;
    [urlData writeToFile:dataPath options:0 error:&error];

    if(!error)
    {

        if (![defaults objectForKey:@"places images path"]) {
            [defaults setObject:path forKey:@"places images path"];

            [defaults synchronize];
        }

        ZipArchive* za = [[ZipArchive alloc] init];
        if( [za UnzipOpenFile:dataPath] )
        {
            BOOL ret = [za UnzipFileTo:path overWrite: YES];
            if (NO == ret){} [za UnzipCloseFile];

            NSLog(@"Successful unzip of: %@",@"/Library/Caches/TKAPlacesImages.zip");
        }
        else
        {



            NSLog(@"Could not find zip file.");

        }
    }
    else
    {
        NSLog(@"Error saving file %@",error);
    }
添加了PHP代码

function zip_image_files($images) {

    // Prepare File
    $file = tempnam("tmp", "zip");
    $zip = new ZipArchive();
    $zip->open($file, ZipArchive::OVERWRITE);

    $imagesCount = count($images);
    $imagesString = '';

    for($i=0; $i < $imagesCount; $i++)
    {
        // Stuff with content
        $imagesString = ".." . $images[$i];

        if(file_exists($imagesString))
        {
            $zip->addFile($imagesString);
        }
        else
        {
            echo $imagesString;
        }

    }//end for

    // Close and send to users
    $zip->close();
    header('Content-Type: application/zip');
    header('Content-Length: ' . filesize($file));
    header('Content-Disposition: attachment; filename="file.zip"');
    readfile($file);
    unlink($file); 

}
//end function
函数压缩图像文件($images){
//准备文件
$file=tempnam(“tmp”、“zip”);
$zip=新的ZipArchive();
$zip->open($file,ZipArchive::OVERWRITE);
$IMAGESCONT=计数($images);
$imagesString='';
对于($i=0;$i<$ImageScont;$i++)
{
//充满内容
$imagesString=“…”。$images[$i];
如果(文件_存在($imagesString))
{
$zip->addFile($imagesString);
}
其他的
{
echo$imagesString;
}
}//结束
//关闭并发送给用户
$zip->close();
标题(“内容类型:应用程序/zip”);
标题('Content-Length:'.filesize($file));
标题('Content-Disposition:attachment;filename=“file.zip”);
readfile($file);
取消链接($文件);
}
//端函数
编辑
我的函数返回一个19.2MB的zip文件。但是,在我的应用程序数据文件中,zip文件是0字节。

我打赌(1)
urlData
是零,因此没有写入任何内容,因为没有要写入的内容;或者(2)
urlData
不是压缩数据,解压缩失败。第一个问题可能是实际问题,因为您说您没有看到任何书面文件。

这段代码有多远?发生了什么事?@rmaddy我为您编辑了我的问题。您正在调用
writeToFile:
,没有进行错误检查。添加错误检查!它返回一个BOOL,告诉您写入是否成功。另外(与此问题无关,但稍后它会咬到您),当您将路径存储在用户默认值中时,您假定为硬编码路径
@“/Library/Caches/TKAPlacesImages”
。不太好。我补充了一些可能有用的信息。