我有一个使用 ARC 开发的 iPhone 应用程序。我的文档目录中有一个文件夹,其中包含一堆图像,我需要将其压缩并通过电子邮件发送。我的项目使用ARC。
有人有任何对我有帮助的示例代码/资源链接吗?
我在网上查了一下,发现与 ARC 不兼容——即使它声称是。
从此链接下载 Objective-Zip、MiniZip 和 ZLib 并将其拖入您的项目http://code.google.com/p/objective-zip/downloads/list http://code.google.com/p/objective-zip/downloads/list(目标-zip)。导入文件:
ZipFile.h,
ZipException.h,
文件压缩信息.h,
ZipWriteStream.h,
ZipReadStream.h,
兹库文件
使用此代码。请看下面:
NSString *stringPath1 = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]];
NSString *FileName=[stringPath1 stringByAppendingPathComponent:@"Your file name"];
NSString *stringPath=[stringPath1 stringByAppendingPathComponent:[@"Your file name" stringByAppendingFormat:@".zip"]];
NSArray *files = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:FileName error:&error];
ZipFile *zipFile = [[ZipFile alloc]initWithFileName:stringPath mode:ZipFileModeCreate];
for(int i = 0;i<files.count;i++){
id myArrayElement = [files objectAtIndex:i];
NSLog(@"add %@", myArrayElement);
NSString *path = [FileName stringByAppendingPathComponent:myArrayElement];
NSDictionary *attributes = [[NSFileManager defaultManager]attributesOfItemAtPath:path error:&error];
NSDate *Date = [attributes objectForKey:NSFileCreationDate];
ZipWriteStream *streem = [zipFile writeFileInZipWithName:myArrayElement fileDate:Date compressionLevel:ZipCompressionLevelBest];
NSData *data = [NSData dataWithContentsOfFile:path];
[streem writeData:data];
[streem finishedWriting];
}
[zipFile close];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)