我需要通过电子邮件(或任何其他共享应用程序)发送一个 zip 文件,并且该 zip 文件受密码保护。当我下载那个 zip 文件时,它会要求输入密码。我正在使用 SSZipArchive
来压缩我的 html 文件。
NSString *txtFilePath0 = [documentsDirectory stringByAppendingPathComponent:@"medical_checkups.html"];
NSArray *inputPaths = @[txtFilePath0];
[SSZipArchive createZipFileAtPath:archivePath withFilesAtPaths:inputPaths withPassword:@"123456"];
NSString *archivePath = [documentsDirectory stringByAppendingString:@"/medical_checkups.zip"];
MFMailComposeViewController *_mailController = [[MFMailComposeViewController alloc] init];
if ([MFMailComposeViewController canSendMail])
{
[_mailController setMessageBody:@""
isHTML:NO];
[_mailController setMailComposeDelegate:self];
[_mailController addAttachmentData:[NSData dataWithContentsOfFile:archivePath]
mimeType:@"application/zip"
fileName:@"medical_checkups.zip"];
[self presentViewController:_mailController animated:YES completion:nil];
}
但现在当我尝试解压缩我的 zip 文件时,没有密码弹出窗口。我也无法打开我的 zip 文件。
最佳答案
对于密码保护,您必须使用此库 https://cocoapods.org/pods/SSZipArchive
然后将您的 Zip 文件转换为 NSData
并在 Mail composer 中附加
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *WritableDBPath= [documentsDirectory stringByAppendingPathComponent:kFilename];
NSData *data = [NSData dataWithContentsOfFile:WritableDBPath];
[picker addAttachmentData:data mimeType:@"application/zip" fileName:@"/abc.zip"];
[picker setSubject:@"Database"];
[picker setMessageBody:@"Database testing" isHTML:NO];
[self presentModalViewController:picker animated:YES];
---已编辑
存档工具 提取(解压缩)您的文件时会显示错误,因为它的密码 protected 。
那么,然后将您的 zip 文件解压缩到您的应用程序之外
请使用 the-unarchiver Mac应用
---已编辑
@Priti Kanauziya , 我找到了新的解决方案。在 SSZipArchive 中有一个新类 AES 和它的默认 YES 。我们需要将其设置为 NO 。
关于ios - 如何使用密码保护在电子邮件上发送 zip 文件并在 objective-c 中通过电子邮件解压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51421377/