gpt4 book ai didi

iphone - 如何在 iPhone SDK 中压缩文件夹?

转载 作者:太空狗 更新时间:2023-10-30 03:30:30 25 4
gpt4 key购买 nike

在我的应用程序中,我正在拍摄 ImageView 的屏幕截图,然后将这些屏幕截图保存在应用程序的文档文件夹中。现在我想通过电子邮件发送所有这些具有相同文件夹结构的图像。压缩所有文件夹包含图像然后将 zip 文件附加到邮件将解决问题,但我如何压缩这些文件夹然后将它们附加到邮件?

感谢任何帮助!

最佳答案

我已经使用此代码为我的应用程序的文档目录创建了一个 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");

关于iphone - 如何在 iPhone SDK 中压缩文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8150185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com