Reputation: 295
I need to send a zip file via Email (or any other sharing app), and the zip file is password protected. When I download that zip file it will ask for the password. I am using SSZipArchive
to zip my html file.
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];
}
But now when I try to unzip my zip file there is no popup for password. I also can't open my zip file.
Upvotes: 1
Views: 600
Reputation: 4815
For password protection you have to use This library https://cocoapods.org/pods/SSZipArchive
Then get your Zip file convert to NSData
and Attach in 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];
---Edited
Archive Utility Will show you error while extracting (unzip) your file because its password protected.
So , to unzip the Your zip file outside your Application then
please use the-unarchiver Application for Mac
---Edited
By @Priti Kanauziya, I found the new solution . In SSZipArchive there is a new class AES and its YES by default . And we need to set it NO .
Upvotes: 2