compress or zip iOS sqlite Database

送分小仙女□ 提交于 2021-02-07 10:37:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!