0

我正在生成文档目录中的数据的 zip 文件,问题是它在 iphone 模拟器上运行良好,但相同的编码不适用于 iphone 实际设备,即电话 5

这是我的代码片段

ZipArchive *archiver = [[ZipArchive alloc] init];
[archiver CreateZipFile2:archivePath];
for(NSString *path in subpaths)
{
    NSString *longPath = [exportPath stringByAppendingPathComponent:path];
    if([fileManager fileExistsAtPath:longPath isDirectory:&isDir] && !isDir)
    {
        [archiver CreateZipFile2:longPath];
        [archiver addFileToZip:longPath newname:path];
    }
}
BOOL successCompressing = [archiver CloseZipFile2];

我试图用谷歌搜索但它没有提供任何帮助请指导我谢谢

4

2 回答 2

0

您好尝试以下代码:

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* dPath = [paths objectAtIndex:0];
NSString* txtfile = [dPath stringByAppendingPathComponent:@"test.txt"];
NSString* zipfile = [dPath stringByAppendingPathComponent:@"test.zip"];
ZipArchive* zip = [[ZipArchive alloc] init];
BOOL ret = [zip CreateZipFile2:zipfile];
ret = [zip addFileToZip:txtfile newname:@"test.txt"];//zip
if( ![zip CloseZipFile2] )
{
    zipfile = @"";
}
[zip release];
NSLog(@"The file has been zipped");
于 2013-09-13T08:15:57.057 回答
0

试试这个:

   NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];


     NSString *toCompress = @"AccReport1.html";
    NSString *pathToCompress = [documentsDirectory stringByAppendingPathComponent:toCompress];

    NSFileManager *fileManager = [NSFileManager defaultManager];



    NSString *zipFilePath = [documentsDirectory stringByAppendingPathComponent:@"myZipFileName.zip"];

    ZipArchive *za = [[ZipArchive alloc] init];
    [za CreateZipFile2:zipFilePath];  

    [za addFileToZip:pathToCompress newname:toCompress];
    [za release];

确保你写了这一行:NSFileManager *fileManager = [NSFileManager defaultManager];

于 2013-09-13T11:09:43.067 回答