ios - 如何使用密码保护在电子邮件上发送 zip 文件并在 objective-c 中通过电子邮件解压缩

标签 ios objective-c zip

我需要通过电子邮件(或任何其他共享应用程序)发送一个 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 。

enter image description here

那么,然后将您的 zip 文件解压缩到您的应用程序之外

请使用 the-unarchiver Mac应用

---已编辑

@Priti Kanauziya , 我找到了新的解决方案。在 SSZipArchive 中有一个新类 AES 和它的默认 YES 。我们需要将其设置为 NO 。

关于ios - 如何使用密码保护在电子邮件上发送 zip 文件并在 objective-c 中通过电子邮件解压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51421377/

相关文章:

ios - AVAssetWriter startSessionAtSourceTime 不接受 CMTIme 值

ios - iOS 5 下的 Haskell : suppressing output

ios - 将流字节转换为字符串

.net - 是否有像 Xceed Real-Time Zip 这样实时压缩的免费压缩实用程序?

python - 如何从两个单独的列表中获取两个值进行打印(python)

ios - 在 Swift 中更改 VC 问题。如何在选项卡栏 Controller 中的 View 之间传递数据?

ios - 与 PowerBI Embedded Report (WKWebView) 交互时的 GreyBox

ios - 无法在 IOS 中多次执行 X 分钟的函数调用

c# - 如何使用 C# 解压缩压缩文件?

ios - 如何在 UIPageViewController 中从一页动画到另一页时设置 View 的背景颜色