在我的申请,我以图像查看的屏幕截图,然后我保存在application.Now的文件夹的屏幕截图我想通过电子邮件发送相同文件夹结构,所有这些图像他们in.Zipping都包含文件夹图像,然后将zip文件附加到邮件将解决问题,但我如何压缩这些文件夹,然后将它们附加到邮件?如何在iPhone SDK中压缩文件夹?
任何帮助表示赞赏!
在我的申请,我以图像查看的屏幕截图,然后我保存在application.Now的文件夹的屏幕截图我想通过电子邮件发送相同文件夹结构,所有这些图像他们in.Zipping都包含文件夹图像,然后将zip文件附加到邮件将解决问题,但我如何压缩这些文件夹,然后将它们附加到邮件?如何在iPhone SDK中压缩文件夹?
任何帮助表示赞赏!
我已经使用这个代码来创建文件的zip文件我的应用程序的目录,它的工作
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [paths objectAtIndex:0];
BOOL isDir=NO;
NSArray *subpaths;
NSString *exportPath = docDirectory;
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:exportPath isDirectory:&isDir] && isDir){
subpaths = [fileManager subpathsAtPath:exportPath];
}
NSString *archivePath = [docDirectory stringByAppendingString:@"/test.zip"];
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 addFileToZip:longPath newname:path];
}
}
if([archiver CloseZipFile2])
NSLog(@"Success");
else
NSLog(@"Fail");
我用ZipArchive在过去的成功。
这是相当ligyweight和使用简单,支持密码保护,ZIP中的多个文件,以及压缩&解压缩。
的基本用法是:
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"ZipFileName" ofType:@"zip"];
ZipArchive *zipArchive = [[ZipArchive alloc] init];
[zipArchive UnzipOpenFile:filepath Password:@"xxxxxx"];
[zipArchive UnzipFileTo:{pathToDirectory} overWrite:YES];
[zipArchive UnzipCloseFile];
[zipArchive release];
这是解压文件夹/文件。压缩文件夹同样容易。压缩文件(或fodler)
BOOL ret = [zip CreateZipFile2:l_zipfile];
// OR
BOOL ret = [zip CreateZipFile2:l_zipfile Password:@"your password"]; //
//if the Password is empty, will get the same effect as [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:l_photo newname:@"photo.jpg"];
if(![zip CloseZipFile2])
{
// error handler here
}
[zip release];
我也听说过ObjectiveC-Zip也。
ZipArchive是一个Objective-C类,以压缩或解压缩的压缩文件,这是开放的源代码“MiniZip”碱基。
它可用于iPhone应用程序开发和可可在Mac OSX上也是如此。
要创建可以使用ZipArchive 下载源代码,并将其添加到您的项目,还可以添加libz.x.dylib一个zip文件(看看维基)。
在你的头文件然后加:#import "ZipArchive/ZipArchive.h"
要创建一个zip文件很简单,只需使用下面的代码:
BOOL ret = [zip CreateZipFile2:l_zipfile];
// OR
BOOL ret = [zip CreateZipFile2:l_zipfile Password:@"your password"]; //
//if the Password is empty, will get the same effect as [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:l_photo newname:@"photo.jpg"];
if(![zip CloseZipFile2])
{
// error handler here
}
[zip release];
它只形成所有文件包含在一个zip格式的文件,但它不会减小大小zip文件。我们如何缩小zip文件的大小?请指导。提前致谢。 – Nico
简易模式:添加ZipArchive到您的项目,则:
NSString* zip = ...;
NSString* dir = ...;
[SSZipArchive createZipFileAtPath: zip withContentsOfDirectory: dir];
谢谢..它的工作:) – Yogi
瑜伽士我面临着同样的情况。你可以分享你的代码 – thavasidurai
我认为他已经使用了上述代码@thavasidurai – Robin