我正在生成我的数据的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];
我试着用谷歌搜索,但它没有给予任何帮助 请指导我 感谢
答案 0 :(得分: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");
答案 1 :(得分: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];