问题
People,
How Can I Zip my iOS app's sqlite database? Because I'm trying to sinc it with the cloud but im having some troubles...
Which classes I'm supposed to use to zip it ? please help me out!
回答1:
You can use ZipArchive, its a objective c wrapper to zip/unzip - http://code.google.com/p/ziparchive/
for zip :-
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* dPath = [paths objectAtIndex:0];
NSString* txtfile = [dPath stringByAppendingPathComponent:@"test.txt"];
NSString* zipfile = [dPath stringByAppendingPathComponent:@"test.zip"];
ZipArchive* zip = [[ZipArchive alloc] init];
BOOL ret = [zip CreateZipFile2:zipfile];
ret = [zip addFileToZip:txtfile newname:@"test.txt"];//zip
if( ![zip CloseZipFile2] )
{
zipfile = @"";
}
[zip release];
NSLog(@"The file has been zipped");
回答2:
you can use Zlib which is available at: http://code.google.com/p/objective-zip/
来源:https://stackoverflow.com/questions/10720980/compress-or-zip-ios-sqlite-database