Ziparchive不适用于iphone设备
我正在生成文档目录中数据的zip文件,问题是它与iphone模拟器配合得很好,但相同的编码不适用于iphone实际设备phone 5 这是我的代码片段Ziparchive不适用于iphone设备,iphone,ziparchive,Iphone,Ziparchive,我正在生成文档目录中数据的zip文件,问题是它与iphone模拟器配合得很好,但相同的编码不适用于iphone实际设备phone 5 这是我的代码片段 ZipArchive *archiver = [[ZipArchive alloc] init]; [archiver CreateZipFile2:archivePath]; for(NSString *path in subpaths) { NSString *longPath = [exportPath stringByAppend
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];
我试着用谷歌搜索,但没有任何帮助
请引导我
谢谢您好,请尝试以下代码:
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");
试试这个:
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]您是否解决了您的问题?不,我尝试了与您相同的方法,但没有解决问题,而是在没有zip的情况下完成并将其发送到服务器