In my Application,I am taking screenshots of image View and then I am saving those screen shots in document folder of the application.Now I want to Email all those images with the same folder structure they are in.Zipping all the folders containing the images and then attaching the zip file to the mail will solve the problem but how can I zip these folders and then attach them to the mail?
Any help is appreciated!
Open the Files app, then choose a location like On My iPhone or iCloud Drive. Tap Select, then choose one or more files. Tap More, then tap Compress. If you selected one file, a ZIP file with the same filename saves to that folder.
To place multiple files into a zip folder, select all of the files while hitting the Ctrl button. Then, right-click on one of the files, move your cursor over the “Send to” option and select “Compressed (zipped) folder”.
To zip (compress) a file or folder Locate the file or folder that you want to zip. Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder. A new zipped folder with the same name is created in the same location.
I have used this code to create a zip file of the documents directory of my app and it worked
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");
ZipArchive is an Objective-C class to compress or uncompress zip files, which is base on open source code "MiniZip".
It can be used for iPhone application development, and cocoa on Mac OSX as well.
see this : http://code.google.com/p/ziparchive/downloads/list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With